I have a custom type that i fill with data from two tables. I've tried the following to join two tables, this normally works. But the group by and count is causing errors:
public List<sLoadingList> GetOrdersforLoadingByWard(string _mywCode, DateTime _orderDate, int _periodId)
{
var _formattedDate = _orderDate.Date;
List<sLoadingList> query = (from o in CateringEntities.Orders
join i in CateringEntities.OrderItems
on o.OrderId equals i.OrderId
where o.LocationsLookUp.WardCode.Equals(_mywCode) &&
DbFunctions.TruncateTime(o.Date) == _formattedDate && o.Period == _periodId
select new sLoadingList()
{
ItemId = i.ItemId,
ItemName = i.Item.ItemName,
ItemType = i.ItemType,
Quantity = i.Item.ItemName.Count()
}).GroupBy(i => i.ItemId).Select(i => i.FirstOrDefault()).ToList();
return query.ToList();
This is currently giving error:
{"DbExpressionBinding requires an input expression with a collection
ResultType.\r\nParameter name: input"}
But if i remove :
Quantity = i.Item.ItemName.Count()
the query runs ok.