开发者

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜