0
比較日期的正確eSQL語法是什麼?比較實體SQL中的日期
等效LINQ到實體表達會是這個樣子:
var lastYearsShipments = from p in MyDataServiceContext.Products
where p.ShipDate.Value.Year == DateTime.Now.Year - 1
select p;
比較日期的正確eSQL語法是什麼?比較實體SQL中的日期
等效LINQ到實體表達會是這個樣子:
var lastYearsShipments = from p in MyDataServiceContext.Products
where p.ShipDate.Value.Year == DateTime.Now.Year - 1
select p;
他們說這是acceptable to answer your own question,所以這裏去...
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>
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);