我使用实体 ObjectSet 类构建 select 和 where 条件
对象查询。
ObjectQuery<DbDataRecord> query = context.TestEnt.Select("it.BuySell, "
+ "it.DepoTerm").Where("Datediff(day,it.RunDateTime,'22-11-2012')=0" );
var a = query.ToList();
foreach (var tmp in a)
{
Console.WriteLine(tmp["BuySell"].ToString());
}
我想在我的 where 条件中使用 datediff 函数, 我该怎么做?
最佳答案
试试这个:
var query = context.TestEnt
.Where("DiffDays(it.RunDateTime,'22-11-2012')=0" );
.Select("it.BuySell, it.DepoTerm")
您可能必须对字符串传递的数据调用 CreateDataTime
才能使其正常工作。 Here是 ESQL 中所有支持的日期函数的列表。
您还可以使用 Linq-to-entities:
var query = context.TestEnt
.Where(x => SqlFunctions.DateDiff("day", x.RunDateTime,'22-11-2012') == 0)
.Select(x => new { x.BuySell, x.DepoTerm });
关于c# - Entity SQL DateDiff 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8462544/