-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Query: Translate IQueryable.Concat/Union/Intersect/Except/etc. to server #6812
Comments
@simpleway2016 In general the LINQ implementation of EF Core only attempts to translate specific patterns to equivalent SQL expressions for relational databases. In the particular case of Changing this to producing a single SQL query on the server isn't currently a top priority because we believe that for many common scenarios (e.g. for the sample queries you posted) there isn't a significant difference. Could you elaborate on what scenario you think performing the union on the server would be more useful for you? |
var q1 = from m in db.Table1
select new
{
name = m.Name,
};
var q2 = from m in db.Table2
select new
{
name = m.Name,
};
q1 = q1.Concat(q2);
var result = q1.OrderBy(m=>m.Name).Skip(1000).Take(10).ToArray(); If i use the ef core like that,it also make two sql string , excute two dbcommand,and concatenate the results in memory, and then excute "OrderBy(m=>m.Name).Skip(1000).Take(10)", |
I would really like to see this feature too. As @simpleway2016 said above, paging results of a union in the database is much more efficient. |
It would have a significant performance difference if there is a large amount of latency between the client and the server (such as being in a different timezone). |
Consider a banking application where it needs to display a number of types of transactions, each of which has its own specific properties but also shares some common data with other types, in one page, with paging and sorting. This is a perfect case where translating the concat query into one union all statement would be needed. |
Please put this feature on a higher priority ,We really need this feature, it should have much higher priority than |
@ajcvickers what's the state of this ? |
@John0King It's still scheduled for 2.1, but as far as I am aware @smitpatel has not implemented it yet. (It's always possible it won't make 2.1 given we don't know the full schedule yet.) |
Prompt to me, where I can read all supported things for EF Core? (e.t. Concat....) |
@roji please reverify that SQL Server does not support take/order by within subset operations. I believe it should, but not if you only specify order by without a top/take. I believe: |
@kingmotley trying to run your 2nd query ( Are you seeing a different behavior? |
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. dotnet#16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes dotnet#6812 Fixes dotnet#13196 Fixes dotnet#16065 Fixes dotnet#16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. #16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes #6812 Fixes #13196 Fixes #16065 Fixes #16165
Sorry, I didn't have access to an instance of Sql Server when I originally posted, but was pretty certain that you could do two unions of a limited set. I assumed (wrongly) that since views have the requirement that they can only have a TOP clause when there is also an ORDER BY, then the 2nd query would work. But in practice, using a view like that in a query (and then inlining it) would look more like the following, which does work:
|
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. dotnet#16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes dotnet#6812 Fixes dotnet#13196 Fixes dotnet#16065 Fixes dotnet#16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. dotnet#16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes dotnet#6812 Fixes dotnet#13196 Fixes dotnet#16065 Fixes dotnet#16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. #16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes #6812 Fixes #13196 Fixes #16065 Fixes #16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. dotnet#16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes dotnet#6812 Fixes dotnet#13196 Fixes dotnet#16065 Fixes dotnet#16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. #16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes #6812 Fixes #13196 Fixes #16065 Fixes #16165
* Include/nav rewriting is now supported. * We now push down to subquery when OrderBy, Take or Skip are applied to set operations, to avoid using the hack where ColumnExpression with no table alias was used. #16244 was opened to track for post-3.0. * Added missing support for union over subselect projection mappings. * Added Other type to SetOperationType so that providers can define extra set operations (e.g. PostgreSQL `INTERSECT ALL`, `EXCEPT ALL`). Completes #6812 Fixes #13196 Fixes #16065 Fixes #16165
* We no longer allow ColumnExpression without table alias * Set operations over operands with different types have been disabled for now. * We now push down set operations into a subquery on Orderby, Skip or Take, which shouldn't be necessary (#16244). * Some test consolidation and cleanup. Continues #6812
* We no longer allow ColumnExpression without table alias * Set operations over operands with different types have been disabled for now. * We now push down set operations into a subquery on Orderby, Skip or Take, which shouldn't be necessary (#16244). * Some test consolidation and cleanup. Continues #6812
* We no longer allow ColumnExpression without table alias * Set operations over operands with different types have been disabled for now. * We now push down set operations into a subquery on Orderby, Skip or Take, which shouldn't be necessary (#16244). * Some test consolidation and cleanup. Continues #6812
That's good suggestion for Sql Server, but we use MySQL |
EF version:1.0.1.0
I watch the sql string by ILogger, the sql string is not union two table, the dbconnection will excute two dbcommand for each table like this:
command 1:
command 2:
at EF 6.1 version, it's make a sql string like this:
The text was updated successfully, but these errors were encountered: