gpt4 book ai didi

c# - Linq to EF - 不支持的函数

转载 作者:行者123 更新时间:2023-11-30 13:10:34 28 4
gpt4 key购买 nike

我正在使用由 Entity Framework 数据源支持的 Linq 进行查询。

我收到以下错误:

LINQ to Entities does not recognize the method 'Double Sqrt(Double)' method, and this method cannot be translated into a store expression.

这是我的函数的简化版本(我的版本更复杂,使用了 ACos、sin、cos 和其他 C# 数学类函数)。

  var objects =
from n in context.Products.Where(p => p.r == r)
let a = Math.Sqrt((double)n.Latitude)
where a < 5
orderby a
select n;

return objects.Take(100).ToList();

我认为问题可能与 Linq to EF(和 SQL 数据源)与 Linq to SQL 相比支持的函数集有限的情况有关。我对此比较陌生,所以我不是 100% 确定。

谁能给我一个正确方向的指示?

干杯,

最佳答案

尝试 SquareRoot SqlFunctions

中定义的函数
    var objects =
from n in context.Products.Where(p => p.r == r)
let a = SqlFunctions.SquareRoot((double)n.Latitude)
where a < 5
orderby a
select n;

return objects.Take(100).ToList();

关于c# - Linq to EF - 不支持的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9354716/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com