abp icon indicating copy to clipboard operation
abp copied to clipboard

Using SQL and MongoDB in the same project

Open luisp88 opened this issue 6 years ago • 5 comments

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 image in DependsOn to ProjectDbMigratorModule, so breakpoint hitting AddMongoDbContext OK. image Declared one FullAuditedAggregateRoot<> and added as IMongoCollection image 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 :(

luisp88 avatar Apr 06 '20 23:04 luisp88

Required services was replaced by each other.

hitaspdotnet avatar Apr 06 '20 23:04 hitaspdotnet

I there anyway to use abp to add both services without using services.Replace() in abp's AddXDbContext?

luisp88 avatar Apr 07 '20 16:04 luisp88

@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.

maliming avatar Apr 08 '20 01:04 maliming

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?

luisp88 avatar Apr 08 '20 21:04 luisp88

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.

hikalkan avatar Apr 15 '20 07:04 hikalkan