Using SQL and MongoDB in the same project
I downloaded a project template for EFc and I'm using SQL Server OK.
I want to use both, SQLS and MongoDB, so created another project with its ..DbModule.cs and ..DbContext.cs
Added
in DependsOn to ProjectDbMigratorModule, so breakpoint hitting AddMongoDbContext
Declared one FullAuditedAggregateRoot<> and added as IMongoCollection
Also have the connection string in .DbMigrator's appsettings.json
Problem: No database creation! Downloaded MongoDB project template, changed the connection string and that project does create the database :(
Required services was replaced by each other.
I there anyway to use abp to add both services without using services.Replace() in abp's AddXDbContext?
@luisp88
I think EF Core and Mongodb cannot work together in the same project.
It can be used when deploying the module as a remote service.
If someone wants to use dbentities and mongocollections in same solution and inject "sql entities" and "mongo collections" in same appservice:
What I just did was to create another project similar as EntityFrameworkCore but for MongoDB. Added it to DependsOn in DbMigratorModule and HttpApiHostModule (keeped DbMigrations clean without dependson MongoDb).
In the new project module, added in ConfigureServices:
context.Services.AddMongoDbContext<FichaMedicaMongoDbContext>(options =>
{
options.AddDefaultRepositories(includeAllEntities: true);
});
and also DependsOn AbpMongoDbModule.
Declared a collection in its MongoDbContext, added dataseeders and everything works ok.
One question: each time I run the app and use some collection (.CoutnAsync .ToList or InsertAsync), the first executions always enters on .CreateModel of my new MongoDbContext class (with dbcontext that doesn't happen). Is it ok?
the first executions always enters on .CreateModel of my new MongoDbContext class (with dbcontext that doesn't happen). Is it ok?
Yes, it is OK.
As I understand you could be able to make it working. So, closing the issue.