-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EF Core 5.0 Many-to-Many generating singular table names and plural column names #23258
Comments
@mhosman EF isn't actually pluralizing or singularizing anything here. The table names come from your entity type names. (If you had DbSet properties for these types, then the names would come from those.) The FK names are based on the navigation properties on each end of the relationship. |
Thanks for the response. There's a way to change this manually? Like in fluent API? Thanks! |
Sorry @ajcvickers, not able to find how to change column names without specifying the CLR class (only was able to find a way to change the table name in the docs, no the column names). Anyway... this behaviour is kind of weird... Since this are always collections, if resulting values are based on the navigation properties, you'll always get pluralized values (unless you name a collection as singular). Also, in the docs, you have pluralized values in your classes, but the resulting SQL it's okay (singular). So... I don't understand where is the issue. |
@mhosman You need to use this overload of modelBuilder.Entity<Customer>()
.HasMany(p => p.Colors)
.WithMany(p => p.Customers)
.UsingEntity<Dictionary<string, object>>(
"CustomerColor",
j => j
.HasOne<Color>()
.WithMany()
.HasForeignKey("ColorId"),
j => j
.HasOne<Customer>()
.WithMany()
.HasForeignKey("CustomerId")); We use the navigation names in the generated names to make it easier to distinguish them for self-referencing relationships and have a simple naming rule. |
Great @AndriySvyryd thank you very much!! Worked like a charm. Closing!! |
@AndriySvyryd Do we have anything tracking making this easier? I don't (yet) think we made the wrong choice on FK property names, but I do think that many people will want to change them. |
Example:
This is generating a table CustomerColor (singular) with column names in plural: ColorsId, CustomersId
The text was updated successfully, but these errors were encountered: