The data provider used to translate LINQ code to SQL does not understand ToShortDateString . Because of this, you cannot use it in a LINQ query that is sent to the database. You must call this method after the data has been returned from the database:
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 { city = o.city, customersOrderRef = o.customersOrderRef, date = (o.actualDelivery ?? o.plannedDelivery), date1 = (o.actualCease ?? o.actualCease), number = o.number, ordered = o.ordered, postCode = o.postCode, status = s.status, stockCode = o.stockCode, UpdatedByAccount = o.UpdatedByAccount }).ToList() .Select(x => new DataLayer.OrderStatusItem { city = x.city, customersOrderRef = x.customersOrderRef, date = x.date, date1 = x.date1, number = x.number, ordered = x.ordered.DateTime.ToShortDateString(), postCode = x.postCode, status = x.status, stockCode = x.stockCode, UpdatedByAccount = x.UpdatedByAccount };
BTW: There is another solution that creates shorter code:
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 { o, s }).ToList() .Select(x => new DataLayer.OrderStatusItem { city = xocity, customersOrderRef = xocustomersOrderRef, date = (xoactualDelivery ?? xoplannedDelivery), date1 = (xoactualCease ?? xoactualCease), number = xonumber, ordered = xoordered.DateTime.ToShortDateString(), postCode = xopostCode, status = xsstatus, stockCode = xostockCode, UpdatedByAccount = xoUpdatedByAccount };
The difference between the two versions is that the first version queries only those columns from the database you need, where the second version will return all columns from two tables.