0
2つのDbContextクラスといくつかのエンティティがあります。私はこれが複数のDbContextを持つのは良い考えではないことを知っていますが、私は自分のコードを変更するために多くの作業をしなければなりません!だから私の質問は、異なるDbContextを持つ2つのエンティティ間の関係を追加するための最良のシナリオは何ですか?例えば2つの異なるDbContextでテーブル間の関係を追加する方法
IdentityDbコンテキストとユーザエンティティとの間の多くの関係に1とSiteDbContext持つエンティティコメント:
public class User : IdentityUser
{
public DateTime JoinDate { get; set; }
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this,DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
public class IdentityDb : IdentityDbContext<ApplicationUser>
{
public IdentityDb() : base("DefaultConnection", throwIfV1Schema: false)
{
}
public static IdentityDb Create()
{
return new IdentityDb();
}
}
public class Comment
{
public int CommentId { get; set; }
[Required]
[StringLength(900)]
public string CommentText { get; set; }
[DataType(DataType.Date)]
public DateTime CommentDate { get; set; }
}
public class SiteDb: DbContext
{
public SiteDb(): base("DefaultConnection")
{
}
public DbSet<Comment> Comments{ get; set; }
}
[複数のコンテキスト、Entity Framework 6、dbcontextsの参照エンティティ](http://stackoverflow.com/questions/22534560/multiple-contexts-withentity-framework-6-reference-entities-across- dbcontexts) –