ASP.NET Boilerplate multiple databases and DbContexts

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



ASP.NET Boilerplate multiple databases and DbContexts



I want to connect to two databases at once using ASP.NET Boilerplate. I followed this example: https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextEfCoreDemo



The problem is that only the first context will have all the Abp tables on it. The second context is an existing database, which has none of the Abp tables on it.



When I start up the web app, I get this:


System.Data.SqlClient.SqlException: 'Invalid object name 'AbpLanguages'.'



So obviously it is looking for Abp* tables on the second context, but they don't exist there (and they should not). So, what is the correct way to have more than one context, so that it doesn't look for Abp* tables on the second context?



Update



I have created an example application by modifying a clean ASP.NET Boilerplate project generated from a template.



I have tested with a project generated from the template which is API-only, and there it works perfectly. But when API and frontend are combined when generating the project, I am getting these issues where the Abp* tables are looked for on additional contexts.



Dropbox: https://www.dropbox.com/s/19gj8ms0jwz500k/4.0.1.zip?dl=0

Github: https://github.com/FrikkinLazer/MultipleContext.git





The second context can be found under TwoContexts.EntityFrameworkCore -> EntityFrameworkCore -> SecondContext. I added it to github as well.
– Bertus van Zyl
Aug 6 at 5:45






There's no SecondDbContext.
– aaron
Aug 6 at 5:49


SecondDbContext





Its under /src/TwoContexts.EntityFrameworkCore/EntityFrameworkCore/SecondContext/Models/, and it is called TEST1Context
– Bertus van Zyl
Aug 6 at 12:07




1 Answer
1


// using Abp.Zero.EntityFrameworkCore;

public partial class TEST1Context : AbpZeroDbContext<Tenant, Role, User, TEST1Context>

// ...



Abp.Zero.EntityFrameworkCore's AbpZeroDbContext defines the DbSets for Module Zero tables.


Abp.Zero.EntityFrameworkCore


AbpZeroDbContext


DbSet



the second context is an existing database, that have none of the Abp tables on it.



So, what is the correct way to have more than one context, so that it doesnt look for Abp* tables on the second context?



For the second context, subclass Abp.EntityFrameworkCore's AbpDbContext.


Abp.EntityFrameworkCore


AbpDbContext





Thank you. I will test this, and accept the answer when I get a moment.
– Bertus van Zyl
Aug 13 at 11:20





Changing to AbpDbContext works.
– Bertus van Zyl
Aug 14 at 6:27






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard