Linq to EF-不支持的功能 [英] Linq to EF - Unsupported Functions
问题描述
我正在使用由实体框架数据源支持的Linq进行查询.
I'm making a query with Linq, backed by an Entity Framework datasource.
我遇到以下错误:
LINQ to Entities无法识别方法'Double Sqrt(Double)' 方法,并且该方法不能转换为商店表达式.
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#Math类函数).
Here's a simplified version of my function (my version is more complex and uses ACos, sin, cos and other C# Math class functions).
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%.
I think the problem may be related to the situation that Linq to EF (and a SQL datasource) has a limited set of supported function compared to Linq to SQL. I'm relatively new to this so I'm not 100% sure.
谁能给我正确方向的指针?
Can anyone give me a pointer in the right direction?
干杯
推荐答案
尝试 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();
这篇关于Linq to EF-不支持的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!