-
Notifications
You must be signed in to change notification settings - Fork 11
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
Support enum navigations on owned types #16
Comments
Co-Authored-By: Christopher Dresel <[email protected]>
Thank you for the time spent on investigating the issue. We have implemented your proposed changes. Owned entities will be skipped in the initial run of ConfigureEnumLookup and will need to be configured seperately on the Lines 42 to 47 in fa2a51d
Please test the changes with your project either using the latest source or the new NuGet package 2.1.0-beta1 |
I tried this out, it seems to work really well - thanks for implementing this, I appreciate it. |
Consider we define a domain like this:
We configure
Customer
to "own" an instance ofAddress
, and ideally wantAddress
to have a foreign key constraint on aCountryCode
enum lookup table that gets generated by this library:However, trying to create a migration for this causes the following exception to be thrown:
The reason seems to be because of this code in the library, which would try to configure
Address
even though it is owned byCompany
and can only be configured through anOwnedNavigationBuilder
:EntityFrameworkCore.Extensions/src/SpatialFocus.EntityFrameworkCore.Extensions/EnumLookupExtension.cs
Lines 71 to 76 in dc2f146
To support enum properties on owned types, one fix might be to check if the type is owned and skipping configuration on it if that is the case. One way I've found to do this after some quick digging was the following:
If the library bypasses configuration of owned types, it might allow the relationship to be manually configured. After playing around for some time, I found this sort of worked:
This produces the following migration:
Represented diagrammatically:
Do you think it would be feasible to improve support for owned types? I guess this would involve three parts:
Bypassing navigation configuration for owned types (as mentioned above). You'd still do everything else though (i.e. setting up the schema for the enum lookup table and populating it).
Adding some sort of utility method that simplifies manual configuration of foreign key constraints from owned types onto enum lookup types.
Documenting this in the README/samples/etc.
The text was updated successfully, but these errors were encountered: