-
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
[release/7.0] Scaffolding: Fix code for EF6 many-to-many pattern #29793
Conversation
@@ -803,7 +823,7 @@ public System.IFormatProvider FormatProvider | |||
{ | |||
get | |||
{ | |||
return this.formatProviderField; | |||
return this.formatProviderField ; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you expect anything less from a VS tool that generates code. 😉 (The resx one drives me crazy with all its extra whitespace.) I wasn't gonna fight it...
@bricelam could you resolve the merge conflict? |
I see this issue fixed and closed Jan 31 but I am experiencing this issue where it is not reverse engineering two many-to-many tables. It is defining the one entity the DbContext on one table, but not the other and the Class for the entity is not created and the public virtual DbSet class {get; set;} is not defined. No errors are identified in the response to the "dotnet ef dbcontext scaffold" command. Everything else in the database is scaffold correctly. There are two tables in the database that are not scaffolded. They are both many-to-many. Everything else is correct. I'm using version 7.0.13 A scripted table definition of one table is a shown below: USE [########] /****** Object: Table [dbo].[AspNetUserRoles] Script Date: 11/8/2023 3:27:42 PM ******/ SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[AspNetUserRoles]( ALTER TABLE [dbo].[AspNetUserRoles] WITH CHECK ADD CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId] FOREIGN KEY([RoleId]) ALTER TABLE [dbo].[AspNetUserRoles] CHECK CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetRoles_RoleId] ALTER TABLE [dbo].[AspNetUserRoles] WITH CHECK ADD CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetUsers_UserId] FOREIGN KEY([UserId]) ALTER TABLE [dbo].[AspNetUserRoles] CHECK CONSTRAINT [FK_dbo.AspNetUserRoles_dbo.AspNetUsers_UserId] |
Certain patterns of many-to-many join tables that don't follow the EF Core conventions--most notably ones generated by EF6--result in an incomplete model when scaffolding. This fix adds additional handling for these patterns.
Fixes #29544, fixes #29634
Customer impact
Multiple users have reported issues in this area. Some issues can be worked around by applying the fix to custom scaffolding templates. Others require manually updating the code after it's scaffolded. The incorrect models result in runtime exceptions about missing tables and columns.
Regression
Yes. Correct models were scaffolded in EF Core 6.
Testing
Added automated tests covering more unconventional many-to-many join tables.
Risk
Low. Adds back code that I neglected to port as part of the custom templates feature.