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);
}

posted on 2015-10-07 16:28  听哥哥的话  阅读(152)  评论(0编辑  收藏  举报

导航