-
-
Notifications
You must be signed in to change notification settings - Fork 304
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
Add ability to not generate M2M scaffolding with EF Core 6 #1184
Comments
Maybe a combination of the current EF Core 6 state with option "also explicitly generate join tables" would be nice |
Yes, this is what this feature is about! |
This is now available as an advanced option in the latest daily build |
I am not entirely sure where to ask this question so I apologize if this is the wrong location. I want to keep the M2M scaffolding so that I don't have to work with the middle/translational entity. Awesome. Simply keep the option entitled "Use many to many entity (EF Core 6)" under Advanced... as not checked. That said, when choosing this approach, I am presented with generated code that does not build unless I change it. Here is a very simple example to demonstrate my point. User Table with Id, Name When generating the code I get the following at the end of the generated User.cs file ... The line [ForeignKey(nameof(UserId))] does not recognize UserId (the normal red squiggly line in the Visual Studio IDE with the requisite message being "The name 'UserId' does not exist in the current context" . However, if I change the entire line manually to [ForeignKey("UserId")] then everything builds with no issue. The same is true for the Role table. When generating the code I get the following at the end of the generated Role.cs file ... The line [ForeignKey(nameof(RoleId))] does not recognize RoleId. What am I missing here? I feel like there is probably some simple configuration or setup that I am missing that will allow the scaffolding to work as designed. |
Does this just mean that you ticked the option to generate annotations and they are wrongly generated (by EF Power Tools)? |
@Timothy-Siford Please create a new issue and provide a sample SQL script, and/or a repro project (incl SQL script) and I will have a look. |
Thank you!!! That looks exactly to be the issue. With DataAnnotations checked off then it generates incorrectly. |
@Timothy-Siford which EF Core version? |
My teammate decided to jump on this and discovered that it's a combination of enabling both Data Annotations and Handlebars (C#). DataAnnotations adds the [ForeignKey("UserId")] A member of our team had added the Handlebars option awhile ago in preparation for something that was never pursued on this project. When we turn handlebars off, we get [ForeignKey("UserId")] which works perfectly. My teammate does have a test project that shows the issue ... but given that we don't need handlebars, we can turn that off and be good to go. |
Oh! We're using EF Core v6.0.9 |
In case anyone else was trying to find how to use this feature, the option to enable this is called "Use many to many entity" For the CLI version, set the Link to the documentation https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#code-generation |
https://github.com/dotnet/efcore/blob/fb61eb7cfb75253fbae93aeac23c404ba68b83a8/src/EFCore.Design/Scaffolding/Internal/RelationalScaffoldingModelFactory.cs#L658-L660
Override and bypass whole code to detect M2M.
The text was updated successfully, but these errors were encountered: