-
Notifications
You must be signed in to change notification settings - Fork 223
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
Translate array_agg over records/tuples #2633
Comments
I experimented with array_agg a little bit and tried to convert following SQL Statement: SELECT
ARRAY_AGG(DISTINCT "Diagnostic"."DeviceEvents"."Origin") AS origins,
ARRAY_AGG(DISTINCT "Diagnostic"."DeviceEvents"."Device_DeviceId") AS deviceIds
FROM "Diagnostic"."DeviceEvents" into LINQ. I ended up with following statement: var result = await _diagnosticsDbContext.DeviceEvents
.GroupBy(x => 1)
.Select(x => new {
Origins = EF.Functions.ArrayAgg(x.Select(y => y.Origin).Distinct().OrderBy(y => y))
}).FirstOrDefaultAsync(cancellationToken); The GroupBy with the Dummy property is used to have multiple aggregate statements similar to that issue: To my surprise this worked and resulted in following SQL: SELECT array_agg(DISTINCT t."Origin" ORDER BY t."Origin") AS "Origins"
FROM (
SELECT d."Origin", 1 AS "Key"
FROM "Diagnostic"."DeviceEvents" AS d
) AS t
GROUP BY t."Key"
LIMIT 1 Thats not exactly the SQL I started with but should work as expected. Then I added my second aggregation which is part of an owned type: var result = await _diagnosticsDbContext.DeviceEvents
.GroupBy(x => 1)
.Select(x => new {
Origins = EF.Functions.ArrayAgg(x.Select(y => y.Origin).Distinct().OrderBy(y => y)),
DeviceIds = EF.Functions.ArrayAgg(x.Select(y => y.Device.DeviceId).Distinct().OrderBy(y => y))
}).FirstOrDefaultAsync(cancellationToken); This unfortunately resulted in following translation exception:
So I concluded that EF.Functions.ArrayAgg does not work correctly with owned types? |
We support array_agg over a single scalar:
We should also be able to translate this over multiple scalars:
Raised in #2631
The text was updated successfully, but these errors were encountered: