联合不能转换为SQL [英] Union can't be translated to SQL

查看:178
本文介绍了联合不能转换为SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用EFCore 2.2.3,并且已禁用本地评估。

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

我有以下查询

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();

但是如果我尝试

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

我遇到以下错误:


InvalidOperationException:生成警告错误
'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning:
LINQ表达式'Union({来自公司c的
值(Microsoft.EntityFrameworkCore .Query.Internal.EntityQueryable`1 [MagliteTest.Database.Company])
其中([c] .Id == 10)select [c]})'无法翻译,将对
进行评估本地。。
通过将事件ID'RelationalEventId.QueryClientEvaluationWarning'传递给
'DbContext.OnConfiguring'中的'ConfigureWarnings'方法或
'AddDbContext'中的事件ID,可以抑制或记录该异常。

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?

推荐答案

Union / Concat 服务器(SQL)转换尚不支持(从EF Core 2.x开始)。

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

#6812查询可跟踪此问题:翻译IQueryable.Concat / Union / Intersect / Except / etc。

根据该链接,它计划在EF Core 3.0中使用。

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

这篇关于联合不能转换为SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆