entity-framework-core - Union 无法转换为 SQL

标签 entity-framework-core azure-sql-database .net-core-2.2

我使用的是 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/

相关文章:

.net-core - azure webjob : Read appSettings. json 并将配置注入(inject) TimerTrigger

c# - Entity Framework : Passing String Parameter to FromSql Statement in Version 2. 2

c# - SQL错误: Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths. Entity Framework 核心

msbuild - 通过 BACPAC 将 SQL Server 2012 数据库复制到 SQL Azure(用于持续集成)

c# - 数据未插入到 Azure 上托管的 SQL Server 数据库中

sql-server - Azure SQL : Keep alive option

c# - ASP.NET Core 模型绑定(bind)行为切换

c# - EF 核心自引用

.net - EF Core 处理多个预订请求并发的理想方法

mysql - 生成的列 'UserCode' 无法引用自动增量列。埃夫核心