-
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
Issue with serialized Json Array/Lists #29677
Comments
Currently you can store data as List/Array of types mapped to JSON, like in your configuration. Problem is in the query - we don't support At the moment you can:
|
Hmm, I see. Most of the problem right now comes from the migration from previous versions since it was possible to just apply some filters in the JSON and then do a projection. Often configuration would be similar to this: protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(u =>
{
u.ToTable("User");
u.HasKey(x => x.Id);
u.Property(c => c.Comments)
.HasConversion(new JsonPropertyConversion<ImmutableList<Comments>>());
});
} Anyway, looking foward for this feature to be implemented. In meantime, assuming that Owned such as protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<VwUserQuery>(u =>
{
u.ToView("vwUserQuery");
u.HasNoKey();
u.OwnsMany(c => c.Comments, ownedType =>
{
ownedType.Property(d => d.CommentType)
.HasConversion(new EnumToNumberConverter<CommentType, int>());
ownedType.ToJson();
});
});
} Asking because as far I know, Owned types need a primary key. |
In EF 6 JSON support was done through a workaround using converter (presumably to a string), so from EF6 perspective JSON object was just a scalar and some things would translate. In EF7 we decided to represent them as owned types so translation is much more complicated (and missing for now). In the meantime, you can still use the old approach if that's blocking your migration to EF7 - it should work just as well. wrt question about views - you can already have JSON entities where the owner is mapped to a view, but all the JSON entities must also map to the same view. |
Duplicate of #28616 |
Recently I've been trying to upgrade to the lastest EF 7, since its said to support serialized Json columns, however, I didn't find any info about what are the current limitations.
My question is, does it currently supports serialized json Arrays or Lists? I'm going to try to write a simple example
Model:
Configuration:
Query:
Often I ended up getting an exception similar of those:
In this case,
List<Comments> Comments
should be stored in the database as a serialized Json column in the User's tableHere is an example of the json:
I'm not quite sure if it's currently a limitation or if I'm just missing some configuration.
The text was updated successfully, but these errors were encountered: