EntityFramework6.Npgsql
EntityFramework6.Npgsql copied to clipboard
Distinct() ignores OrderBy()
Is this a bug or am I using it wrong?
var emails = await _dataContext
.Users
.OrderBy(user => user.Updated)
.Where(user => user.IsActive)
.Select(user => user.Email)
.Distinct()
.Take(100)
.ToListAsync();
Generates:
SELECT "Alias2"."email" FROM (SELECT DISTINCT "Extent1"."email" FROM "public"."users" AS "Extent1" WHERE "Extent1"."isactive" = TRUE LIMIT 100) AS "Alias2"
So the order by Updated is ignored.
However, if I skip the Distinct(), then I get the following (correct) query:
SELECT "Extent1"."email" FROM "public"."users" AS "Extent1" WHERE "Extent1"."isactive" = TRUE ORDER BY "Extent1"."updated" ASC LIMIT 100
I'm using EntityFramework6.Npgsql 3.1.1