Union can't be translated to SQL

做~自己de王妃 提交于 2019-12-08 02:34:25

问题


I'm using EFCore 2.2.3 and I have disabled local evaluation.

I have the following queries

var query1 = companyContext.Companies.Where(c => c.Name == name);
var query2 = companyContext.Companies.Where(c => c.Id == 10);

If i execute them on their own they work correctly.

await query1.ToListAsync();
await query2.ToListAsync();

But if i try to

var result = await query1.Union(query2).ToListAsync();

i get the following error:

InvalidOperationException: Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'Union({from Company c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MagliteTest.Database.Company]) where ([c].Id == 10) select [c]})' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.

Is union not supported on entity framework core?


回答1:


Union / Concat server (SQL) translation is not supported yet (as of EF Core 2.x).

The issue is tracked by #6812 Query: Translate IQueryable.Concat/Union/Intersect/Except/etc. to server.

According to that link, it's scheduled for EF Core 3.0.



来源:https://stackoverflow.com/questions/55494748/union-cant-be-translated-to-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!