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.73k stars 3.18k forks source link

New virtual method QuerySqlGenerator.GenerateSelect #25900

Open dmitry-lipetsk opened 3 years ago

dmitry-lipetsk commented 3 years ago

Firebird DBMS (v3) has some limitation for arguments of "OFFSET" and "FETCH" in "SELECT" statement - it does not support expressions like "CAST(@param AS INTEGER)"

But it (Firebird) has alternative syntax:

SELECT [FIRST m] [SKIP n] [DISTINCT | ALL] ...

without these limitations.

I not see in current EFCore an any legal way for generation of SQL with FIRST and SKIP:

https://github.com/dotnet/efcore/blob/a0bb25fec68c07e7c123ffba28224548099f4ea9/src/EFCore.Relational/Query/QuerySqlGenerator.cs#L174-L181

Could you move line with

_relationalCommandBuilder.Append("SELECT "); 

into separated new virtual function GenerateSelect?

I will override this function and append the generation of FIRST, SKIP.


Firebird DBMS supports an additional variant for this task - ROWS. Native Firebird provider for EFCore uses this statement in their code.

But usage of "ROWS" requires additional "+1" and uses long.MaxValue for describing unlimited number, so it looks less preferred than "FIRST/SKIP".


Of course, I may copy the body of QuerySqlGenerator.VisitSelect into my code (this is my current variant) and resolve this problem, but may be new method "GenerateSelect" will be usefully into another tasks.

Thanks.

smitpatel commented 3 years ago
smitpatel commented 3 years ago

Since this is new API, unlikely to happen in 6.0 (too late in release), so for 6.0 you should override VisitSelect and copy paste the method body. The new API will be available from 7.0

dmitry-lipetsk commented 3 years ago

Since this is new API, unlikely to happen in 6.0 (too late in release), so for 6.0 you should override VisitSelect and copy paste the method body.

Ok. Already done.

Sorry that I not inform about this problem early.

You may close this issue.