Skip to content
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

Sqlite provider: IQueryable.Average() breaks after calling IQueryable.Select() containing window function #25

Open
AdamIzon opened this issue Jan 19, 2025 · 1 comment

Comments

@AdamIzon
Copy link

AdamIzon commented Jan 19, 2025

Example:

var blockades = _dbContext.Blockades;
var testQuery = blockades.Select(b => EF.Functions.RowNumber(EF.Functions.Over().OrderBy((long)b.BlockadeStartIndex)));
var average = testQuery.Average();

throws: 'SQLite Error 1: 'misuse of window function ROW_NUMBER()'.'

I assume it's forming a query like this:

SELECT AVG(CAST(ROW_NUMBER() OVER(ORDER BY CAST("b"."BlockadeStartIndex" AS INTEGER)) AS REAL))
FROM "Blockade" AS "b"

which also throws "misuse of window function ROW_NUMBER()" when I execute the above query from the "DB Browser for Sqlite" GUI client

@AdamIzon AdamIzon changed the title IQueryable.Average() breaks after calling IQueryable.Select() containing window function Sqlite provider: IQueryable.Average() breaks after calling IQueryable.Select() containing window function Jan 19, 2025
@AdamIzon
Copy link
Author

can confirm EF Core is generating this sql code when calling "Average"

      SELECT AVG(CAST(ROW_NUMBER() OVER(ORDER BY CAST("b"."BlockadeStartIndex" AS INTEGER)) AS REAL))
      FROM "Blockade" AS "b"

after configuring ef core to log to console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant