小编utu*_*upu的帖子

如何正确实现其他实体对身份用户的引用?

我正在使用具有自己上下文的 Identity。

public class ApplicationUser : IdentityUser {
    // some custom fields
}

public class IdentityContext : IdentityDbContext<ApplicationUser> {
   //...
}
Run Code Online (Sandbox Code Playgroud)

我还有其他一些像这样的实体

public class Comment{
   public int Id {get;set;}
   public string Message{get;set;}
   public DateTime Time{get;set;}
}
Run Code Online (Sandbox Code Playgroud)

我的其他上下文使用的

public class MyContext :DbContext {
   public DbSet<Comment> Comments { get; set; }
   //... other DbSets
}
Run Code Online (Sandbox Code Playgroud)

题。我希望我的 Comment 实体具有作者属性,所以我会有类似的东西

public class Comment{
   public int Id {get;set;}
   public string Message{get;set;}
   public DateTime Time{get;set;}
   public virtual ApplicationUser Author {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

但是 ApplicationUser 位于不同的上下文中,尽管在同一个数据库中。我打赌这是不可能的。

如何正确实现这一点?我应该将 DbSets …

c# asp.net-mvc entity-framework dbcontext asp.net-identity

3
推荐指数
1
解决办法
2006
查看次数