codefirst 关系处理

1.http://www.cnblogs.com/libingql/archive/2013/01/31/2888201.html

2.多对多

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//多对多
Database.SetInitializer<CmsDbContext>(null);

modelBuilder.Entity<Article>()
.HasMany(e => e.Tags)
.WithMany(e => e.Articles)
.Map(m =>
{
m.ToTable("ArticleTag");
m.MapLeftKey("ArticleId");
m.MapRightKey("TagId");
});

base.OnModelCreating(modelBuilder);
}

原文地址:https://www.cnblogs.com/kexb/p/4858881.html