我使用的是 EFCore 2.2.3,我已禁用本地评估。
我有以下问题
var query1 = companyContext.Companies.Where(c => c.Name == name);
var query2 = companyContext.Companies.Where(c => c.Id == 10);
如果我自己执行它们,它们就会正常工作。
await query1.ToListAsync();
await query2.ToListAsync();
但如果我尝试
var result = await query1.Union(query2).ToListAsync();
我收到以下错误:
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'.
Entity Framework 核心不支持联合吗?
最佳答案
Union
/Concat
服务器 (SQL) 转换尚不支持(从 EF Core 2.x 开始)。
问题由 #6812 Query: Translate IQueryable.Concat/Union/Intersect/Except/etc. to server 跟踪.
根据该链接,它计划用于 EF Core 3.0。
关于entity-framework-core - Union 无法转换为 SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55494748/