[英]About DbContext in an ASP.NET Identity environment
Following up this post , I have a question to ask. 跟进这篇文章 ,我有一个问题要问。
If I create the class: 如果我创建类:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(): base("DefaultConnection")
{
...
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
...
}
}
That means I have to add all my business logic model domain classes into that DbContext
or it is possible to add a second one? 这意味着我必须将所有业务逻辑模型域类添加到该
DbContext
或者可以添加第二个类?
It is possible to have another DbContext
but the question is whether you want to. 可能有另一个
DbContext
但问题是您是否想要。 See Entity Framework: One Database, Multiple DbContexts. 请参阅实体框架:一个数据库,多个DbContext。 Is this a bad idea?
这是一个坏主意吗?
So in your case, if the entities in your domain model are separate from the IdentityDbContext
then by all means create a new one for those entities. 因此,在您的情况下,如果域模型中的实体与
IdentityDbContext
是分开的,则一定要为这些实体创建一个新实体。 If they rely on anything from IdentityDbContext
you will need to use that context for your domain entities. 如果他们依赖
IdentityDbContext
任何内容,则将需要将该上下文用于域实体。 Otherwise you wouldn't be able to query across both. 否则,您将无法在两者之间进行查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.