把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的更多相关文章

  1. Entity Framework Core的坑:Skip/Take放在Select之前造成Include的实体全表查询

    今天将一个迁移至 ASP.NET Core 的项目放到一台 Linux 服务器上试运行.站点启动后,浏览器打开一个页面一直处于等待状态.接着奇怪的事情发生了,整个 Linux 服务器响应缓慢,ssh命 ...

  2. Entity Framework Core 软删除与查询过滤器

    本文翻译自<Entity Framework Core: Soft Delete using Query Filters>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意 ...

  3. 【EF】Entity Framework Core 软删除与查询过滤器

    本文翻译自<Entity Framework Core: Soft Delete using Query Filters>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意 ...

  4. Entity Framework Core 生成跟踪列

    本文翻译自<Entity Framework Core: Generate tracking columns>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 注意:我使用的是 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Entity Framework Core Like 查询揭秘

    在Entity Framework Core 2.0中增加一个很酷的功能:EF.Functions.Like(),最终解析为SQL中的Like语句,以便于在 LINQ 查询中直接调用. 不过Entit ...

随机推荐

  1. [源码解析] PyTorch 分布式之弹性训练(7)---节点变化

    [源码解析] PyTorch 分布式之弹性训练(7)---节点变化 目录 [源码解析] PyTorch 分布式之弹性训练(7)---节点变化 0x00 摘要 0x01 变化方式 1.1 Scale-d ...

  2. CS5211|CS5211参数|eDP转LVDS转换器芯片

    CS5211概述 CS5211是一个eDP到LVDS转换器,配置灵活,适用于低成本显示系统.CS5211与eDP 1.2兼容,支持1车道和2车道模式,每车道速度为1.62Gbps和2.7Gbps.CS ...

  3. Java EE数据持久化框架作业目录(作业笔记)

    第1章 MyBatis入门>>> 1.1.4 在Eclipse中搭建MyBatis基本开发环境 1.2.5 使用MyBatis查询所有职员信息 1.3.3 获取id值为1的角色信息. ...

  4. 每天学一点——while循环(2)、for循环

    while循环(2) while+continue 打印数字的话相信朋友们在python中不会一个个的print吧 eg: 或者是打印列表里的元素 eg 这种方法只适用于你知道里面有多少个元素, 不然 ...

  5. XML解析的四种方式

    1.说明 XML是EXtensible Markup Language, 即可扩展标记语言, 是一种通用的数据交换格式, 它的平台无关性.语言无关性.系统无关性, 给数据集成与交互带来了极大的方便. ...

  6. 计算机系统3-> 现代计算机基石 | 图灵机理论

    在理解CPU之前,我们有必要先了解一下现代计算机理论的基石--图灵机,这个抽象模型决定了现代计算机可以被实现.这个模型的工作原理也投射到了CPU的工作实现上.图灵机的知识可深可浅,换句话说,上手容易, ...

  7. linux 之 expect 交互操作(自动输入密码)

    场景 需要实现执行一个命令,并自动输入密码. 实现 通过expect命令实现 spawn               交互程序开始后面跟命令或者指定程序expect               获取匹 ...

  8. Selenium_截图(16)

    selenium截图有两种方式 截取全屏 get_screenshot_as_file(filename):将截图转化成文件保存到本地,filename为保存的文件路径 get_screenshot_ ...

  9. Pytest_简介与安装(1)

    一.Pytest简介 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但更灵活.官方网站优点简介: 非常容易上手,入门简单,文档丰富,文档中有很多实例可 ...

  10. minio + kkFileView 实现在线预览

    minio上传的pdf之类文件不支持预览,地址在浏览器访问时会直接下载,现在搭配kkFileView文件预览 1.minio查看之前的安装方式 2.kkFileView安装 docker方式 1.拉取 ...