dotnet / dotnet/efcore

Support projecting out complex JSON types after Distinct

Open
#36,421 0 comments 0 reactions 0 assignees View on GitHub
area-json area-query
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

See test ComplexJsonCollectionSqlServerTest.Distinct_projected:

```c#
public virtual Task Distinct_projected(QueryTrackingBehavior queryTrackingBehavior)
=> AssertQuery(
ss => ss.Set().OrderBy(e => e.Id).Select(e => e.RelatedCollection.Distinct().ToList()),
assertOrder: true,
elementAsserter: (e, a) => AssertCollection(e, a, elementSorter: r => r.Id),
queryTrackingBehavior: queryTrackingBehavior);
```

When Distinct is applied over a complex type (no key/identity), we generally just add all the columns to be identifiers, to properly recognize when the principal changes when loading joined results etc. But JSON columns currently aren't supported as identifiers. Compare with owned entity JSON for possible solutions/workarounds.

See TODO in SelectExpression.ApplyDistinct() where we currently set `nonProcessableExpressionFound = true` for JSON complex types, causing the identifiers to get cleared and therefore disabling projections.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.