When using LINQ to get data from a list I encounter this error. How can this be fixed?
Value cannot be null. Parameter name: source
var nCounts = from sale in sal
select new
{
SaleID = sale.OrderID,
LineItem = from sli in sale.LineItems
group sli by sli.Item into ItemGroup
select new
{
Item = ItemGroup.Key,
Weeks = ItemGroup.Select(s => s.Week)
}
};
foreach (var item in nCounts)
{
foreach (var itmss in item.LineItem)
{
// MessageBox.Show(itmss.Item.Name);
itemsal.Add(new Roundsman.BAL.WeeklyStockList(itmss.Item.Name.ToString(),
itmss.Item.Code.ToString(),
itmss.Item.Description.ToString(),
Convert.ToInt32(itmss.Item.Quantity), 2, 2, 2, 2, 2, 2, 2, 2, 2));
}
}
Error which i got after execution my LINQ I got that type of result (one line, orginally):
System.Linq.Enumerable.WhereSelectListIterator<Roundsman.BAL.Sale, <>f__AnonymousType1<int,System.Collections.Generic.IEnumerable <<>f__AnonymousType0<Roundsman.BAL.Items.Item,System.Collections.Generic.IEnumerable <Roundsman.BAL.WeeklyRecord>>>>>