Entity Framework Core的坑,Select后再对导航属性进行查询或Select前进行Skip/Take
把asp.net core的项目发布到ubuntu上了,运行的时候出现了如下警告:
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'where [g.ResBaseInfo].ResType.Equals(Hotel)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Skip(__p_3)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Take(__p_4)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[10106]
The Include operation for navigation '[g].ResBaseInfo' is unnecessary and was ignored because the navigation is not reachable in the final query results. See https://go.microsoft.com/fwlink/?linkid=850303 for more information.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'where [g.ResBaseInfo].ResType.Equals(Hotel)' could not be translated and will be evaluated locally.
warn: Microsoft.EntityFrameworkCore.Query[20500]
The LINQ expression 'Count()' could not be translated and will be evaluated locally.
本来打算不理会的,但是仔细看了下,大概的意思是会把所有数据拉到本地再进行查询处理,如果数据量大了,服务器肯定遭不住,还是分析代码找到了原因。
错误在于先在一个公共方法里select出了基础数据,然后在Controller中再次根据条件进行where,如果where的是导航属性中的属性,就会报上面的警告。修改了代码,把对导航属性的where语句放到select前,问题解决。
public IQueryable<ResBaseInfoView> GetResBaseInfoViewQueryable(Lang lang, ResType resType = 0)
{
var jquery = _context.ResBaseInfoMultipleLanguage
//.Include(g => g.ResBaseInfo)
//.ThenInclude(g => g.AreaCode)
.Where(g => !g.ResBaseInfo.IsDelete && g.Language.Equals(lang)); if (resType != 0)
{
jquery = jquery.Where(g => g.ResBaseInfo.ResType == resType);
} var result = jquery
.Select(rbml => new ResBaseInfoView
{
ID = rbml.ResBaseInfoID,
AddAccountID = rbml.ResBaseInfo.AddAccountID,
AreaCodeID = rbml.ResBaseInfo.AreaCodeID,
IsDelete = rbml.ResBaseInfo.IsDelete,
Language = rbml.Language,
MLID = rbml.MLID,
UpdateTime = rbml.ResBaseInfo.UpdateTime,
ImageName = rbml.ResBaseInfo.ImageName,
Name = rbml.Name,
ResType = rbml.ResBaseInfo.ResType,
ResTypeName = rbml.ResBaseInfo.ResType.GetDescription(lang),
AreaName = rbml.ResBaseInfo.AreaCode.GetML_Name(lang),
Address = rbml.Address,
AddTime = rbml.ResBaseInfo.AddTime,
Lng = rbml.ResBaseInfo.Lng,
Lat = rbml.ResBaseInfo.Lat,
ZoomLevel = rbml.ResBaseInfo.ZoomLevel,
IsShow = rbml.ResBaseInfo.IsShow,
MobilePhone = rbml.MobilePhone,
Telephone = rbml.Telephone,
Sequence = rbml.ResBaseInfo.Sequence
}); return result;
}
Entity Framework Core的坑,Select后再对导航属性进行查询或Select前进行Skip/Take的更多相关文章
- Entity Framework Core的坑:Skip/Take放在Select之前造成Include的实体全表查询
今天将一个迁移至 ASP.NET Core 的项目放到一台 Linux 服务器上试运行.站点启动后,浏览器打开一个页面一直处于等待状态.接着奇怪的事情发生了,整个 Linux 服务器响应缓慢,ssh命 ...
- Entity Framework Core 软删除与查询过滤器
本文翻译自<Entity Framework Core: Soft Delete using Query Filters>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意 ...
- 【EF】Entity Framework Core 软删除与查询过滤器
本文翻译自<Entity Framework Core: Soft Delete using Query Filters>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意 ...
- Entity Framework Core 生成跟踪列
本文翻译自<Entity Framework Core: Generate tracking columns>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意:我使用的是 ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 更新关系数据
Updating related data¶ 7 of 7 people found this helpful The Contoso University sample web applicatio ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 读取关系数据
Reading related data¶ 9 of 9 people found this helpful The Contoso University sample web application ...
- Working with Data » Getting started with ASP.NET Core and Entity Framework Core using Visual Studio » 排序、筛选、分页以及分组
Sorting, filtering, paging, and grouping 7 of 8 people found this helpful By Tom Dykstra The Contoso ...
- Working with Data » 使用Visual Studio开发ASP.NET Core MVC and Entity Framework Core初学者教程
原文地址:https://docs.asp.net/en/latest/data/ef-mvc/intro.html The Contoso University sample web applica ...
- Entity Framework Core Like 查询揭秘
在Entity Framework Core 2.0中增加一个很酷的功能:EF.Functions.Like(),最终解析为SQL中的Like语句,以便于在 LINQ 查询中直接调用. 不过Entit ...
随机推荐
- Understanding and Improving Fast Adversarial Training
目录 概 主要内容 Random Step的作用 线性性质 gradient alignment 代码 Andriushchenko M. and Flammarion N. Understandin ...
- IT6516替代方案|CS5212替代IT6516|CapstoneCS5212
IT6516/IT6516BFN:是一款DP显示端口转VGA转换器的嵌入式MCU单片机. IT6516/IT6516BFN结合DisplayPort接收器和三重DAC,通过转换功能支持DisplayP ...
- 使用 JavaScript自定义函数计算出教室的体积大小,其中教室的长、宽、高分别为 8 米、5 米、3 米
查看本章节 查看作业目录 需求说明: 使用 JavaScript自定义函数计算出教室的体积大小,其中教室的长.宽.高分别为 8 米.5 米.3 米 实现思路: 创建 HTML 页面 在页面的 < ...
- 使用用支付宝时,返回的数据中subject为中文时验签失败
解决方法为: 来自为知笔记(Wiz)
- maven pom.xml 的 spring-boot-maven-plugin 红色报错 解决
解决方法,添加对应的spring boot 版本号即可
- vue组件中的.sync修饰符使用
在vue的组件通信props中,一般情况下,数据都是单向的,子组件不会更改父组件的值,那么vue提供.sync作为双向传递的关键字,实现了父组件的变动会传递给子组件,而子组件的carts改变时,通过事 ...
- 实验 1 :Mininet 源码安装和可视化拓扑
实验 1 : Mininet 源码安装和可视化拓扑工具 一 .实验目的 掌握 Mininet 的源码安装方法和 miniedit 可视化拓扑生成工具. 二 .实验任务 使用源码安装 Mininet 的 ...
- Java定时调度
一.实现方式 Timer:单线程,串行: ScheduledExecutor:并行,论询,实现麻烦: Spring Scheduler:适合小任务: JcronTab:按照crontab语法编写的ja ...
- LG1290 欧几里德的游戏
https://www.luogu.com.cn/problem/P1290 博弈论游戏,用到mod. 辗转相除法的过程,会构成n种状态. 到达最后一个状态就赢了. 对于一次过程如果div>1那 ...
- 面试官:为什么 TCP 三次握手期间,客户端和服务端的初始化序列号要求不一样?
大家好,我是小林. 为什么 TCP 三次握手期间,客户端和服务端的初始化序列号要求不一样的呢? 接下来,我一步一步给大家讲明白,我觉得应该有不少人会有类似的问题,所以今天在肝一篇! 正文 为什么 TC ...