Im getting an odd error and I cant fix it. Can someone help?
The below code fails because it dosent like o.ordered.DateTime.ToShortDateString() (it works when that part is commented out). o.ordered is a datetimeoffset. There error it gives is below. I have tried a few diffrent versions like using date and tostring rather than toshortdatestring.
LINQ to Entities does not recognize the method 'System.String ToShortDateString()' method, and this method cannot be translated into a store expression.
var BeOrders = from o in BEdb.onlineOrders
join s in BEdb.order_Statuses
on o.status equals s.ID
where o.custCode == pp.AccountID
select new DataLayer.OrderStatusItem {
city = o.city,
customersOrderRef = o.customersOrderRef,
date = (o.actualDelivery ?? o.plannedDelivery),
date1 = (o.actualCease ?? o.actualCease),
number = o.number,
ordered = o.ordered.DateTime.ToShortDateString(),
postCode = o.postCode,
status = s.status,
stockCode = o.stockCode,
UpdatedByAccount = o.UpdatedByAccount
};
The data provider used to translate the LINQ code to SQL doesn’t understand
ToShortDateString. Because of that, you can’t use it in a LINQ query that is sent to the database. You need to call this method after the data has been returned from the database:BTW: There is another solution that produces shorter code:
The difference between those two versions is that the first version only requests those columns from the database you need where as the second version will return all columns of the two tables.