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 ...
随机推荐
- [炼丹术]YOLOv5目标检测学习总结
Yolov5目标检测训练模型学习总结 一.YOLOv5介绍 YOLOv5是一系列在 COCO 数据集上预训练的对象检测架构和模型,代表Ultralytics 对未来视觉 AI 方法的开源研究,结合了在 ...
- Linux 离奇磁盘爆满解决办法
问题原因&通用解决步骤 频繁收到es数据节点磁盘使用监控告警,到es上查看,磁盘使用率40%,因此登录该告警服务器,df -h 查看,如图 发下根目录使用超过了80%,因此持续告警,按照以往办 ...
- JVM垃圾收集器专题
垃圾收集器:利用垃圾收集算法,实现垃圾回收的实践落地. 1 HotSpot垃圾回收器 HotSpot垃圾回收器有多个,可以配合使用. 1.1 垃圾回收的一些术语 术语: Stop the world ...
- 编写Java程序,以树形结构显示国家-直辖市/省/州信息
返回本章节 返回作业目录 需求说明: 以树形结构显示国家-直辖市/省/州信息 实现思路: 创建显示树形结构的类Tree,在该类中定义Map类型的全局实例属性countryMap,该Map集合用于存放所 ...
- Mysql 8.0版本以上和8.0以下jar包版本 需要注意的 URL连接参数useSSL、serverTimezone 相关问题
在语法上的需要注意的: MySQL 8.0 以下版本 - JDBC 驱动名及数据库 URL static final String JDBC_DRIVER = "com.mysql.jdbc ...
- 自学java,如何快速地找到工作
本人最近一直在帮零基础的java开发者提升能力和找工作,在这个过程中,发现零基础的java程序员,在自学和找工作时,普遍会出现一些问题,同时在实践过程中,也总结出了一些能帮零基础java开发尽快提升能 ...
- PPT2010制作翻牌动画
原文: https://www.toutiao.com/i6492653280676545037/ 新建一张空白幻灯片 选择"插入"选项卡,"插入"功能组,&q ...
- node之module与fs文件系统
命令行窗口(小黑屏).cmd窗口.终端.shell 开始菜单 --> 运行 --> CMD --> 回车 常用的指令: dir 列出当前目录下的所有文件 cd 目录名 进入到指定的目 ...
- SQLAlchemy完全入门
最近想要学习SQLAlchemy, 发现网上的中文文档大多是机翻的, 读起来特别变扭, 因此对照着最新的英文文档梳理了一遍, 写下来记录一下 目前SQLAlchemy的版本为1.4.x, 风格处于1. ...
- SYCOJ1613递归函数
题目-递归函数 (shiyancang.cn) 记忆化dfs,注意dp的限制范围 #include<bits/stdc++.h> using namespace std; const in ...