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 ...
随机推荐
- 【Java例题】3.4求a+aa+aaa+aaaa+... ...+aa...a(n个
4. package chapter3; import java.util.*; public class demo4 { public static void main(String[] args) ...
- Entropy Search for Information-Efficient Global Optimization
目录 概 主要内容 的估计 的估计 Hennig P, Schuler C J. Entropy search for information-efficient global optimizatio ...
- Java——HashMap集合详解
第一章 HashMap集合简介 1.1 介绍 HashMap基于哈希表的Map接口实现,是以key-value存储形式存在,即主要用来存放键值对.HashMap 的实现不是同步的,这意味着它不是线程安 ...
- 【2021/12/31】uniapp之安卓原生插件开发教程
uniapp之安卓原生插件开发教程 准备 hbuilderX,下载 app离线SDK,下载 Andorid Studio,安卓官方或中文社区 证书(可以自己准备,也可以使用android Studio ...
- 基于Spring MVC + Spring + MyBatis的【医院就诊挂号系统】
资源下载:https://download.csdn.net/download/weixin_44893902/21727306 一.语言和环境 1.实现语言: JAVA语言. 2.环境要求: MyE ...
- gPRC基本介绍
1.说明 gRPC英文全名为Google Remote Procedure Call, 即Google远程过程调用, 是Google发布的一个高性能.通用的开源RPC框架, 2.gRPC定义 gRPC ...
- javascript中逻辑运算(||,&&,!)
作为一个后端开发的程序员,一直就对JavaScript情有独钟,作为一门前后端通吃的语言,必须赞一下.而且之前很长一段时间都有在做JavaScript,一路都是和ie8死磕,磕完又找低版本的谷歌磕,坑 ...
- Python常用功能函数系列总结(三)
本节目录 常用函数一:词频统计 常用函数二:word2vec 常用函数三:doc2vec 常用函数四:LDA主题分析 常用函数一:词频统计 # -*- coding: utf-8 -*- " ...
- IE8和IE9下textarea滚动选中的问题
在IE8和IE9下如果textarea设置了样式overflow-y:auto;就不可以滚动选中了,应该样式写成overflow:auto;有了纵向滚动实际上就不会出现横向滚动的情况,也没有必要ove ...
- node之module与fs文件系统
命令行窗口(小黑屏).cmd窗口.终端.shell 开始菜单 --> 运行 --> CMD --> 回车 常用的指令: dir 列出当前目录下的所有文件 cd 目录名 进入到指定的目 ...