比较日期的正确 eSQL 语法是什么?
等效的 LINQ-to-Entities 表达式如下所示:
var lastYearsShipments = from p in MyDataServiceContext.Products
where p.ShipDate.Value.Year == DateTime.Now.Year - 1
select p;
比较日期的正确 eSQL 语法是什么?
等效的 LINQ-to-Entities 表达式如下所示:
var lastYearsShipments = from p in MyDataServiceContext.Products
where p.ShipDate.Value.Year == DateTime.Now.Year - 1
select p;
他们说回答你自己的问题是可以接受的,所以这里......
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 文档
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);