I’m getting some data from my database and using linq to calculate sums and counts and group the data.
This is what I have:
var si = _repository.GetAllByDate(date);
var cs = from s in si
group s by s.Name into g
select new { Comm = g.Key, SIList = g.ToList(), Count = g.Count() };
i now need to pass cs to a method in another class so that I can extract Comm, SIList and Count for each item in the group, what type do I pass it as? IEnumerable doesn’t work. The actual linq group result type seems to be:
{System.Linq.Enumerable.WhereSelectEnumerableIterator<System.Linq.IGrouping<Model.Domain.MasterData
.MyItem,Model.Domain.SI<>f__AnonymousTyped<Model.Domain.MasterData.MyItem,System.Collections.Generic.List<Model.Domain.SI>,int>>}
Any ideas? I effectively want to pass cs as a variable and iterate through it there.
You’ll need to create a type that matches the definition of your anonymous type, if it’s going to be used in different scopes.
EDIT: I supposed we can assume that the list will be of
Stringso I’m editing for that. If that’s the wrong type you’ll need to change theIList<T>definition accordingly.