ASP.NET Boilerplate多个数据库和DbContext [英] ASP.NET Boilerplate multiple databases and DbContexts
问题描述
我想使用ASP.NET Boilerplate一次连接到两个数据库.我遵循以下示例: https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextEfCoreDemo
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
问题在于,只有第一个上下文将具有所有Abp表.第二个上下文是现有数据库,上面没有任何Abp表.
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'.'
因此,显然,它正在第二个上下文中查找Abp *表,但是它们在那里不存在(并且不应存在).那么,拥有多个上下文而不在第二个上下文中查找Abp *表的正确方法是什么?
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?
我通过修改从模板生成的干净的ASP.NET Boilerplate项目创建了一个示例应用程序.
I have created an example application by modifying a clean ASP.NET Boilerplate project generated from a template.
我已经测试了从模板生成的仅API的项目,并且在这里可以完美地工作.但是,当在生成项目时将API和前端结合在一起时,我遇到了这些问题,需要在其他上下文中查找Abp *表.
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
Dropbox: https://www.dropbox.com/s/19gj8ms0jwz500k/4.0.1.zip?dl=0
Github: https://github.com/FrikkinLazer/MultipleContext.git
推荐答案
// using Abp.Zero.EntityFrameworkCore;
public partial class TEST1Context : AbpZeroDbContext<Tenant, Role, User, TEST1Context>
{
// ...
}
第二个上下文是现有数据库,上面没有任何Abp表.
the second context is an existing database, that have none of the Abp tables on it. 那么,拥有多个上下文的正确方法是什么,这样它就不会在第二个上下文中查找Abp *表? 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 这篇关于ASP.NET Boilerplate多个数据库和DbContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!Abp.Zero.EntityFrameworkCore
的
Abp.EntityFrameworkCore
的Abp.EntityFrameworkCore
's AbpDbContext
.