ASP.NET Boilerplate multiple databases and DbContexts

asp.net-core aspnetboilerplate c# dbcontext entity-framework-core

Question

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

1
2
8/10/2018 5:20:07 PM

Accepted Answer

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

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.

3
8/10/2018 5:10:01 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow