James
James

Reputation: 2610

How to modify mapping name in many-to-many assossiation

When I create an many to many assossiation on two entities, there will be a relationship table created contains the two entities' primary key in the database. But the name of the column seems no sence, how to modify them?

eg. an Article table and a Blog table, the relationship table will contains two columns' like Article_ArticleID and Blog_BlogID

I want to modify the name at mapping window, but I find it read only, anyone can help?

Thanks in advance!

Upvotes: 1

Views: 70

Answers (1)

artwl
artwl

Reputation: 3582

you can use:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>()
        .HasMany(b => b.Articles)
        .WithMany(a => a.Blogs)
        .Map
        (
            m =>
            {
                m.MapLeftKey("BlogID");
                m.MapRightKey("AritcleID");
                m.ToTable("BlogArticle");
            }
        );
    base.OnModelCreating(modelBuilder);
}

enter image description here

Upvotes: 1

Related Questions