So. I've got a list Property that groups values with identical names;
List<IGrouping<string, MyItemDTO>> MyList { get; set; }
It's initially populated from a database by means of an IQueryable<>
.
But say I wanted to add a new item to this list using code, how would I go about that? Since IGrouping is an interface, I can't exactly new it up like;
IGrouping<string, MyItemDTO> newGroup = new IGrouping<string, MyItemDTO>();
MyList.Add(newGroup);
That doesn't work. I'd like to know, 'what does?' How do I get a new item in there?
Many thanks.
EDIT:
A little perspective:
Imagine having two or more cities. These cities have a few respective streets with matching names. IGrouping<,>
ensures that the street name appears only once in the List. Therefore the data-bound Combobox
doesn't repeat any values (typically because the end user won't know to what city the street belongs to).
My view has two Combobox
es. One for street, the other for city. Should a street be selected, the viewmodel will select the corresponding city, unless the street group contains more that one street within it. At that point, the user will be prompted to manually select which city the street resides in.
I figured that IGrouping<,>
would suit this purpose seeing as it's the default return type when using the GroupBy() extension method. Still open to suggestions though.