ASP.NET Boilerplate multiple databases and DbContexts

こ雲淡風輕ζ 提交于 2019-12-07 22:19:54

问题


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:


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



来源:https://stackoverflow.com/questions/51650555/asp-net-boilerplate-multiple-databases-and-dbcontexts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!