把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. 一个老菜鸟的年度回忆 & 智能工厂奋斗的第三年,可能有你值得借鉴的

    岁月蹉跎,寒冬的夜晚仍伏案疾书,见论坛中有诸多大神已经开始了一年的总结,突然安奈不住心中的躁动,也想为这今年的奋斗留下只言片语,没有年初的目标总结,没有未来的展望,就想作为一篇日记记录今年项目精力,为 ...

  2. Android 悬浮窗 System Alert Window

    悬浮窗能显示在其他应用上方.桌面系统例如Windows,macOS,Ubuntu,打开的程序能以窗口形式显示在屏幕上. 受限于屏幕大小,安卓系统中主要使用多任务切换的方式和分屏的方式.视频播放,视频对 ...

  3. Swoole 中使用 Lock 实现进程间锁

    注意:不要在 lock 和 unlock 操作中间使用可能引起协程切换的 API. $lock = new Swoole\Lock(SWOOLE_MUTEX); echo "[Master] ...

  4. html 基础 vscode的常用快捷键

    1.ctrl+/ //注释代码 2.文件内容查找替换:ctrl+f ctrl+h ,替换一个ctrl+shift+1,替换所有ctrl+alt+enter 3.移动当前行,向上alt+up(方向键↑) ...

  5. python all用法记录

    all函数可以返回对象中是否所有元素均为True 代码如下:(此处仅做简单记录,日后不忙时再认真总结) >>> print(list(map(lambda x: True if x ...

  6. Flask_安装和配置(一)

    安装Flask pip install flask 一 .创建Flask项目 Flask与Django相比,没有提供任何自动创建项目的操作,所以需要手动创建项目及启动项目的管理文件 例如,创建项目目录 ...

  7. 在CentOS7 安装 jq

    root@: 安装EPEL源: yum install epel-release 安装完EPEL源后,可以查看下jq包是否存在: yum list jq 安装jq: yum install jq 命令 ...

  8. c# - 常量定义与赋值

    1.前言 c#与Java很相似,但是不一样,又与js(JavaScript)相似,但是也不一样,所以我认为c#是Java和 js的孩子. 2.常量定义 字符串: const string = &quo ...

  9. Centos安装rrdtool的yum源

    由于centos的标准组件中是不带rrdtool的,因此我们需要添加一个dag的yum源,以安装rrdtool. 修改/etc/yum.repos.d/CentOS-Base.repo, #vi /e ...

  10. Hystrix的原理与架构

    一.定义 一个开源的延迟与容错框架,用于隔离访问远程服务.第三记库,防止出现级联失败 当某个或某些服务反应慢或者超时严重,主动熔断,当情况好转后,可以自动重连 策略:服务降级.服务限流.服务熔断.服务 ...