0

比较日期的正确 eSQL 语法是什么?

等效的 LINQ-to-Entities 表达式如下所示:

var lastYearsShipments = from p in MyDataServiceContext.Products
                         where p.ShipDate.Value.Year == DateTime.Now.Year - 1
                         select p;
4

2 回答 2

2

他们说回答你自己的问题是可以接受的,所以这里......

var predicate = string.Format(
    "Year(it.ShipDate) == Year(cast('{0}' as System.DateTime)) -1",
    System.DateTime.Now);

var lastYearsShipments = 
    myQuery.Products.Where(predicate); // myQuery is type ObjectQuery<T>

另请参阅:msdn 文档

于 2009-03-02T21:45:26.467 回答
0
string datetimeFormatter = "yyyy-MM-dd HH:mm";

var predicate = string.Format("Year(it.ShipDate) == Year(DATETIME'{0}')) -1", System.DateTime.Now.ToString(datetimeFormatter)); 

var lastYearsShipments = myQuery.Products.Where(predicate); 
于 2010-03-25T16:47:49.027 回答