How do you name a many-to-many relationship table using Fluent Api?

494 Views Asked by At

I have created a many-to-many relationship, and the name the table (the one that has the Id of both records / objects) has doesn't appeal to me.

So how can I name that table using Fluent Api? By a usual table I'd use ToTable("Name"), but how do I do the same thing on this atypical table?

1

There are 1 best solutions below

3
Andrew On

Looks like you still use the ToTable() method in conjunction with the UsingEntity() fluent api:

modelBuilder
    .Entity<Post>()
    .HasMany(p => p.Tags)
    .WithMany(p => p.Posts)
    .UsingEntity(j => j.ToTable("PostTags"));