-2

ADO.NET EF 不支持 Math.Pow 和 Math.Log 之类的东西,所以我想知道如何解决这个问题。我需要能够对使用 ADO.NET EF 的计算值使用 ORDER BY。

4

1 回答 1

2

您可以使用 Entity SQL,但我不推荐它

using System.Data.EntityClient;

EntityConnection conn = new EntityConnection(myContext.Connection.ConnectionString);
conn.Open();
EntityCommand cmd = conn.CreateCommand();
cmd.CommandText = @"Select SqlServer.Power(t.MyValue, 2) From MyEntities.MyTable As t";
var result = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess);
result.Read();
var valuePower2 = result.GetValue(0);
conn.Close();

要执行动态排序依据和 where 子句,请使用Dynamic Linq

于 2009-03-01T03:26:15.710 回答