I am trying to fetch certain database values and store them in a datatable. After that I am applying linq to group by all the data with account number.
I am getting the following error
Cannot implicitly convert type
Try this:
class ListItem
{
public string accountNumber { get; set; }
public List<string> itemNumbers { get; set; }
}
accounts = (from result in dataTable.AsEnumerable() group result by result.Field<string>("accountNumber") into g select new ListItems { accountNumber = g.Key, itemNumbers = g.Select(x => x.Field<string>("<itemNumber>")).ToList() }).ToList();
An explanation is in order:
ListItems
class to ListItem
and the itemNumbers
property to be of type List<string>
ListItem
instance, grouped by the accountNumber
column, and storing all items in the itemNumbers
property