How do I rename columns for a many to many table with composite keys using EF CTP5 code-first?
Here is the sample from the ADO.NET site.
Rename columns in many:many table:
modelBuilder.Entity<Product>()
.HasMany(p => p.Tags)
.WithMany(t => t.Products)
.Map(m =>
{
m.MapLeftKey(p => p.ProductId, "CustomFkToProductId");
m.MapRightKey(t => t.TagId, "CustomFkToTagId");
});
Please extend this ex开发者_如何学运维ample with a second imaginary key (i.e. ProductId2, TagId2) on each of the tables.
For that you just need to map the secondary columns as well:
modelBuilder.Entity<Product>()
.HasMany(p => p.Tags)
.WithMany(t => t.Products)
.Map(m =>
{
m.MapLeftKey(p => p.ProductId, "CustomFkToProductId");
m.MapLeftKey(p => p.ProductId2, "CustomFkToProductId2");
m.MapRightKey(t => t.TagId, "CustomFkToTagId");
m.MapRightKey(t => t.TagId2, "CustomFkToTagId2");
});
精彩评论