You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Why are owned types required to use the ToJson feature?
I suspect this has been asked, but I cannot find any discussion of it.
Scenario
I have a scenario where I am keeping a draft version of an entity as a child property of the entity and stored as JSON. Because the child and the parent are the same type, the property type cannot be owned with OwnsOne or OwnsMany. This is from an MVC5 project I am converting to EF Core 8.
Failed Attempt
I attempted subclassing the entity type so it could be owned, which didn't quite work out. I have two list properties that had to be hidden in the new subclass with new versions of the properties using a subclass of the type in the lists. While it compiled and ran, it created a big complication for my business logic that treats the entity and the draft as the same base type, as it would not see the new properties unless I detect the true type and cast to that type conditionally to reach the right properties. Yuck.
More Questions
I solved my problem by using the tried and true ValueConverter trick, but it left me wondering:
why owned types are required for the ToJson feature in the first place?
why does it matter that the type is used elsewhere in the model?
is this capability planned for a future update?
The text was updated successfully, but these errors were encountered:
@ktownsend-personal The answer to all your questions is basically the same--for the most common uses of JSON, owned types are not a good fit. The team recognizes this, which is why we are implementing complex types, which have value-object semantics--and we will then support mapping to JSON from complex types.
Question
Why are owned types required to use the ToJson feature?
I suspect this has been asked, but I cannot find any discussion of it.
Scenario
I have a scenario where I am keeping a draft version of an entity as a child property of the entity and stored as JSON. Because the child and the parent are the same type, the property type cannot be owned with
OwnsOne
orOwnsMany
. This is from anMVC5
project I am converting toEF Core 8
.Failed Attempt
I attempted subclassing the entity type so it could be owned, which didn't quite work out. I have two list properties that had to be hidden in the new subclass with new versions of the properties using a subclass of the type in the lists. While it compiled and ran, it created a big complication for my business logic that treats the entity and the draft as the same base type, as it would not see the new properties unless I detect the true type and cast to that type conditionally to reach the right properties. Yuck.
More Questions
I solved my problem by using the tried and true
ValueConverter
trick, but it left me wondering:The text was updated successfully, but these errors were encountered: