Closed meikeric closed 2 years ago
@meikeric Thanks for showing an interest in this. Here is some guidance based on our current understanding of how this would be best implemented and general patterns/considerations in the EF Core code.
With regard to your questions about internal classes.
Thanks for the feedback. Regarding the type mapping that seems to be a popular topic of concern: Hypotetically, and assuming it makes it into 2.0, would you be using native types on the provider side, e.g. SQL server?
I'm trying to invision how EF could use SQL Server's new support of JSON_VALUE and JSON_QUERY to offload the work to the DB server. That's essentially what I was trying to encompass with a JsonMap attribute. I hadn't finished working through but I wanted to present a scenario to solicit feedback.
We are closing this issue because no further action is planned for this issue. If you still have any issues or questions, please log a new issue with any additional details that you have.
AFAIK JSON mapping is not supported yet... Therefore, I dug into the EFCore code and came up with the following implementation which has pretty good success and allows me to have a base class with many child classes that maps all the additional class properties that don't have a physical db field into a single field using JSON and deserializes (on the db side using JSON_VALUE or JSON_QUERY if it's a complex type) to the property. The only part left I have to figure out is the JSON serialization on saving.
I had to make copies of Check.cs, CodeAnnotations.cs, and maybe another internal class. If you could make these not "internal" that would be fantastic!
Steps: Create new Attribute
Override the SqlGenerator Factory
Override the SqlGenerator
Replace the IQuerySqlGeneratorFactory in Startup.cs/ConfigureServices
Add a discriminator to my DbContext
And finally in my model, use the JsonMap attribute
And now this all gets magically unwrapped into a typed object on load.
I'd be more than happy to contribute something more refined to EFCore with the teams guidance as I think this is a feature the community would love to use.