开发者

Entity Framework 4.1 RC: Override name of Many to Many join table

开发者 https://www.devze.com 2023-02-18 19:33 出处:网络
In my code I have a many to 开发者_开发知识库many relationship defined using: modelBuilder.Entity<Post>()

In my code I have a many to 开发者_开发知识库many relationship defined using:

modelBuilder.Entity<Post>()
        .HasMany( p => p.Authors ).WithMany();

Post.Authors is an ICollection of User entities.

The ModelBuilder automatically creates a table called PostUsers.

How can I override the table naming convention so that the ModelBuilder names the table PostAuthors when the database is created from the model?

Thanks!


You can use:

modelBuilder.Entity<Post>
    .HasMany(p => p.Authors)
    .WithMany()
    .Map(m => m.ToTable("PostAuthors", "dbo"));
0

精彩评论

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

关注公众号