-
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
Detect simple join tables in reverse engineering and create many-to-many relationships #22475
Comments
Notes from triage:
@ErikEJ Might you consider doing this in the EF Core Power Tools? That would make something available for 5.0. Also, in the future, if you want to do the PR for here, that would be awesome! 😁 |
@ajcvickers I assume that would require changes to code generation, then? |
Ok - I have already reluctantly pulled in some Internal code anyway. Happy to take a PR for this!! |
It would probably require some changes to code gen. Currently there is no processing of SkipNavigations in code gen at all. I think best place to identify and add skip navigation would be RelationalScaffoldingModelFactory (now we are deep in internal territory lol) to add skip navs to model and code gen will handle it as such. |
Hmmm.. where would I specify the table name (since it most likely will not match convention) Assume in fluent config, but how, since there is no EntityType to refer to?? |
modelBuilder.Entity<One>().HasMany(e => e.TwoSkip).WithMany(e => e.OneSkip).UsingEntity(e => e.ToTable("tableName")); EF will fill in actual entity type appropriately, whatever that type would be by convention. (Likely Dictionary<string, object>) |
@smitpatel The provided solution doesn't seem to work in my scenario as the table "FeatureVehicle" contains two columns which has underscore ("Feature_ID" and "Vehicle_VehicleID"). (cc @ajcvickers) When query is executed it throws following exception:
Here are my entities:
|
@bmoteria - Your issue is not related to the issue you are posting on. Please avoid off-topic discussions. Your column names in the join entity does not match what is generated conventionally, so you will need to configure them manually using HasColumnName. |
I am ready for this change, we use database first and it would be great if it automatically did the Many to Many so something like
@ajcvickers |
…Specifications. Because the support for scaffolding many-to-many relationships from the database is not yet added (dotnet/efcore#22475).
…Specifications. Because the support for scaffolding many-to-many relationships from the database is not yet added (dotnet/efcore#22475).
Power Tools simply uses the default CSharpDbContextGenerator.cs, but it hooks into the DatabaseModel generation, and manipulates that in flight. I was looking for a simple way to exclude a table from many-to-many, not include, to allow users to opt out on a per table basis. |
Looking at power tools code, I see that you already have one derived class for |
@smitpatel Perfect! I will consider that if customers ask for it! |
@ErikEJ So it looks like right now you don't need us to add/change things for you? |
@ajcvickers Correct! |
Not to sure how we can vote for this feature, however we have just migrated to .net 5 and have a very large database with a large number of many to many joins, and the current scaffolding has not mapped them correctly at all. To go and manually do all the Join entities is gonna take ages. |
@Zapnologica This is implemented in EF Core 6! |
Oh awesome stuff
I can't wait for that to be released.
…On Fri, 29 Oct 2021, 07:34 Erik Ejlskov Jensen, ***@***.***> wrote:
@Zapnologica <https://github.com/Zapnologica> This is implemented in EF
Core 6!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22475 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA34ZUJ3HV2UP7ETADZ76YDUJI56VANCNFSM4RFGVVXA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
@Zapnologica it will happen within two weeks! |
Hi, although this is a nice feature we have the following scenario, where we have some trouble with it:
Scaffolding the database context fails in this case with the error message that the navigation property Table 'B' cannot be added twice to Table 'A'. It would be nice if the navigation property names could be based on the intersection table name(s) to circumvent this issue. |
@hgsenger This will be fixed in 6.0.1 |
Hi, I take a simple many-to-many relationship. After scaffolding I will take one entity with two Reference navigation and two entities without collection navigation. As I read the documentation, the two entities mave to include the collection navigation.
And dbContext includes only one-to-many relationships
|
I have the same Problem. DBContext only hast one-to-many relationships even thought the database has many-to-many relations. |
@moritzinio please open a new issue, and share your database schema. |
@ErikEJ I will tomorrow thank you. |
@ajcvickers hiya this docs page https://docs.microsoft.com/en-us/ef/core/modeling/relationships?tabs=fluent-api%2Cfluent-api-simple-key%2Csimple-key#many-to-many Points to this workitem which seems to be closed. Is this now fixed or not? perhaps the docs should be updated? |
I don't think its SOLVED, we have the same problem today with the latest version of EF core 6.0.6 (at the moment) scaffolding a Postgresql database with two m-2-m tables... |
@Scionn Please open a new issue and post the schema and command that results in the issue so that we can investigate. |
Maybe missing something here, but I'm baffled at how or why would Microsoft arbitrarily force a set of rules and decide which and when a table will be reverse engineered and when to skip it, without even a flag to supress it. Is there a way to full scaffold using net 6 without this nonsense, other than doing it by hand? thanks |
@RicardOlivo Yes, just use EF Core Power Tools! |
I still want ef core gen class mapping many-many in net 6.0, how to do it
Ef gen:
|
@tuyendam00 I did it using net core 3.1, then copy/pasted into 6. Sad I know. |
@tuyendam00 @RicardOlivo Just use EF Core Power Tools, it has an option to generate the actual entities |
No description provided.
The text was updated successfully, but these errors were encountered: