我有2个DbContexts
,一个管理IdentityUser
和其他模型
课程MyUser
与ApplicationUser
public class ApplicationUser : IdentityUser
{
public virtual MyUser MyUser { get; set; }
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public DbSet<MyUser> MyUsers { get; set; }
}
在模型项目中,我有一个名为Review
的班级,其中评论与MyUser
public class Review
{
public int Id { get; set; }
public int MyUserId { get; set; }
public virtual MyUser MyUser { get; set; }
}
public class MyUser
{
[Key, ForeignKey("ApplicationUser")]
public string ApplicationUserId { get; set; }
public virtual ApplicationUser AppUser { get; set; }
public ICollection<Review> Reviews { get; set; }
}
public class MyContext: DbContext
{
public MyContext() :
base(nameOrConnectionString: "DefaultConnection")
{
}
public DbSet<Review> Reviews { get; set;}
// Do i have to add MyUser DebSet here?
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
我的问题是,MyUser应与评论和ApplicationUser
相关联
评论在MyContext
中被定义,ApplicationUser
中的ApplicationDbContext
被定义为<{1}}
我怎么写关系?在whitch DbContext中,有什么想法吗?