我正在尝试使用 Entity Framework 6 将数学函数发送到 sql server。
我有一个简单的查询:
using(var db = databaseContext)
{
var query = db.Foo.Select(x => Math.Sin(x.bar));
}
但是这给了我一个异常(exception)。
An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code
Additional information: LINQ to Entities does not recognize the method 'Double Sin(Double)' method, and this method cannot be translated into a store expression.
问题是 Entity Framework 不知道如何将 Math.sin 翻译成 Sql Server 等价物。我可以使用任何其他有效的类吗?
最佳答案
我会先从数据库中加载数据,然后在内存中进行这样的计算
using(var db = databaseContext)
{
var listofFoo= db.Foo.toList();
var listofFooSin = listofFoo.Select(x => Math.Sin(x.bar));
}
关于c# - 如何使用 Entity Framework 6 将数学函数发送到 Sql Server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39274589/