dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.81k stars 3.2k forks source link

Primitive collections #30731

Open roji opened 1 year ago

roji commented 1 year ago

This user story tracks support for primitive collections, i.e. the ability to map a property of type int[] to the database, as a JSON array (by default). Where supported, such collections are also fully queryable via the regular LINQ operators.

As a by-product of this, the translation for intParam.Contains(b => b.Property) would be changed from the current IN with constants translation to a string parameter containing an JSON array, which would be unpacked at the database and queried via the standard means. This resolves #13617, which is a long-standing, highly-voted performance issue.

Done in 8.0

Done in 9.0

Backlog

Related issues

vchirikov commented 3 months ago

@roji I'm sorry to bother you, I found that builder.OwnsMany(x => x.ListOfStructsProperty, x => x.ToJson()); doesn't work on net8.0 and I didn't find the issue to track. Should I create it or the issue is already here somewhere?

roji commented 3 months ago

@AndriySvyryd do we have an issue already tracking this? I found #28861 but that seems to be something else (am still not sure exactly what though 😅 )

In any case, we're likely to work on mapping JSON through complex types (as opposed to owned entities), and should make that work there - JSON mapping via owned entity types is likely to be de-prioritized.

AndriySvyryd commented 3 months ago

@vchirikov ~Mapping owned collections to JSON is generally supported. Can you open a new issue that shows the types being mapped, the error that you get and how you expect the JSON to look?~

Oh, I see now. We only allow structs to be mapped as complex types. So as @roji mentioned, be on the lookout for #31252 and #31411

zN3utr4l commented 3 months ago

Do you have any suggestions for implementing a List<List< int>>? since it doesn't work with OwnsMany either.

https://github.com/dotnet/efcore/issues/33913

roji commented 3 months ago

@zN3utr4l nested primitive collection support is tracked by #30713 - that's not currently supported.