Entity framework EF 4.2代码优先。如何命名多对多表?
是否可以在多对多关系中指定表名 例如:Entity framework EF 4.2代码优先。如何命名多对多表?,entity-framework,entity-framework-4,ef-code-first,Entity Framework,Entity Framework 4,Ef Code First,是否可以在多对多关系中指定表名 例如: class A { public int Id { get; set; } // ..... public virtual ICollection<B> BCollection { get; set; } } class B { public int Id { get; set; } // ..... public virtual ICollection<A> ACollecti
class A
{
public int Id { get; set; }
// .....
public virtual ICollection<B> BCollection { get; set; }
}
class B
{
public int Id { get; set; }
// .....
public virtual ICollection<A> ACollection { get; set; }
}
A类
{
公共int Id{get;set;}
// .....
公共虚拟ICollection B集合{get;set;}
}
B类
{
公共int Id{get;set;}
// .....
公共虚拟ICollection ACollection{get;set;}
}
我以为这可能行得通,但显然不行
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<A>().HasMany(x => x.BCollection).WithMany(y => y.ACollection).Map(m => m.ToTable("My_Custom_Name"));
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().HasMany(x=>x.BCollection).WithMany(y=>y.ACollection).Map(m=>m.ToTable(“我的自定义名称”);
}
尝试同时映射列名
modelBuilder.Entity<A>()
.HasMany(x => x.BCollection).WithMany(y => y.ACollection)
.Map(m =>
{
m.ToTable("My_Custom_Name");
m.MapLeftKey("AId");
m.MapRightKey("BId");
});
modelBuilder.Entity()
.HasMany(x=>x.b集合)。WithMany(y=>y.a集合)
.Map(m=>
{
m、 ToTable(“我的自定义名称”);
m、 MapLeftKey(“援助”);
m、 MapRightKey(“投标”);
});