-
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
Sharing JSON column between different generic implementations in TPH inheritance #29456
Comments
@rafalkwol Can you show an example of the data in your table? |
@ajcvickers Let's say it looks something like this in a very simplified form. In reality JSON in "Message" column can be basically anything that can be represented as C# model. Each C# class have different "MessageType" so we can be sure that the "Message" is always structured the same way for each discriminator. |
I was hoping for this as well since they both translates to Here's my sample where I bumped into this; https://github.com/OskarKlintrot/JsonColumn |
You should be able to map this by using JSON column sharing once it's implemented |
@AndriySvyryd Any information on the time it's planned as a feature? I'm guessing not earlier than .NET 8? |
It's not currently planned for any release as it doesn't have any votes (👍 ) |
@rafalkwol note also that .NET/EF 7.0 will be released next week, so definitely no new features are being added to it until then. The next release is EF 8.0 - in a year - which is the earliest where this could be implemented (excluding previews). |
@roji Oh, that's fine. I was just hoping I could make it work somehow right now, but if it's not possible for now than I will just figure this out some other way. Anyway I like the direction where EF Core is going with all the new features being added and it's really becoming better and better with every release in my opinion. I hope the innovation will continue and we will get something even more interesting next time. |
Duplicate of #28592. |
Hello,
Since I heard about the JSON columns in EF Core 7 I was very excited about this feature. I was using JSON as a part of out data structure in SQL Server for quite a while and using it with EF Core was quite cumbersome.
Today I wanted to try it out to check if my use case could benefit from this new feature and so far I can't figure out if it's even an option for me.
So the use case is this. I want to have a table with TPH inheritance. This table will keep records of different messages sent between multiple systems. All the messages have a defined structure so each message will have it's own C# class. I want to keep all the messages in the same table and differentiate them by the discriminator of the record and also be able to query each of them by some of their properties, modify them etc.
Below is the code I tried to use to prototype this:
When I try to create a migration for the above code I get a stack trace like this:
From the information above the thing that comes to my mind is that it's not possible to have a generic base class with a specific property that is treated as a JSON column that have a different type per implementation. Is this true or am I just missing something? Or is there any other way to achive this than the one described?
I know that when using inheritance only the properties with the same type in the derived classes can have the same column mapped to them. I was hoping as JSON columns basically are translated into the same type on the database side this kind of structure would be possible. I would be grateful if someone more in the know could shed some light on this issue.
EF Core version: 7.0.0-rc.2.22472.11
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: Windows 11 Professional
IDE: Visual Studio Code 1.72.2
The text was updated successfully, but these errors were encountered: