Feat/net10: Fixes Owned JSON Entities and Adds Support for the new Complex Properties.#190
Conversation
This reverts commit 8f578e5.
- Call .ToJson() only for the root json entity
- Don't use [Column("name")] overrides for json properties
|
This is amazing work @r-Larch! Thanks for doing this. Regarding your comments:
Regarding that second point, we could either disable support for it for now, or alternatively enable it behind a feature env variable flag. It would be technically supported, but without guarantees that it will not change in future releases, depending on what the EF team does. If they implement it in the base library, we can remove the need for the flag What would you think about this approach? |
|
Hi @artiomchi , You are right, we should mirror the EF implementation and 'throw' in that case. |
| // The following IF condition should therefore never be true in deeper recursions. | ||
| // therefore, we could refactor this check to the caller level only, but we keep it here because once ef core adds support for this scenario, this would be the way to handle it. | ||
| if (complexProperty.ComplexType.IsMappedToJson()) | ||
| { |
There was a problem hiding this comment.
EF does not support complex table-shared properties with a child complex property mapped to JSON.
If we want to mirror the EF implementation, we could throw here if path is not null.
There was a problem hiding this comment.
Going to take that suggestion on and apply it. I've moved the comment above into the if statement to make it more contextually accurate
| else if (constantValue.ColumnProperty is JsonColumn json) | ||
| { | ||
| relationalTypeMapping = relationalTypeMappingSource.FindMapping(json.Column.StoreType); | ||
| relationalTypeMapping = relationalTypeMappingSource.FindMapping(json.Column.ProviderClrType, json.Column.Table.Model.Model, json.Column.StoreTypeMapping); |
There was a problem hiding this comment.
It could be possible that this line-change fixes: #187 Does not handle type conversion/type adapters for pgsql
Requires tests to verify.
Hi @artiomchi ,
I saw your issue EF Core v10 release #186 and would like to help.
As I wrote the initial owned entity logic, I feel responsible for fixing it ;)
This PR fixes the problem with owned JSON entities and adds support for the new complex properties.
The problem with owned JSON entities:
GenerateProviderValueSqlLiteral.INavigationentities.RelationalJsonHelperbased on the public JSON helper for the new complex properties RelationalJsonUtilities and the json serialization logic for INavigation in ModificationCommandSupport for the new complex properties:
I left some comments in the code:
RelationalJsonHelperfor JSON serialization, as I would like to reuse EF Core internals for it, but I could not find any useful public type for it. Maybe you have or can find a better idea?ProcessComplexPropertyrecursive function would be able to handle Complex table shared properties with a child complex property mapped to JSON, but EF Core does not currently support it and throws in OnModelCreating. Maybe we should be more cautious and also throw? What do you think? Allow nested complex properties mapped to JSON with the top complex property using table sharing dotnet/efcore#36558