随笔 - 165, 文章 - 0, 评论 - 18, 阅读 - 22万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

把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前,问题解决。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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;
}

  

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示