I have the following select query in linq:
var something = from te in taskEvidences join e in evidences on te.EvidenceId equals e.Id join tr in taskRequirements on te.TaskListId equals tr.TaskListId join r in newSelectableModule.Requirements on tr.RequirementListId equals r.Requirement.Id select new { Evidence = e, RequirementIndices = r.Index }; Currently it selects an Evidence object along with several Index (int) values, so for example I might get 5 records back, all with the same Evidence object and 5 different indices.
What I want to do it just return a single record with the Evidence object and a List<int> of the indices. I attempted to use grouping, but I keep getting errors about the type can't be inferred from the usage. This is one such attempt:
group new {e, r} by new {e} into g select new { Evidence = g.Key, RequirementIndices = g.SelectMany(x => x.r.Index) }; The error occurs around the SelectMany being assigned to the RequirementIndices property. I've tried several suggests I've found online, but none of them have helped. I assume it is a small error on my part, but I'm going code blind now!
Update:
Exact error:
The type arguments for method 'Enumerable.SelectMany(IEnumerable, Func>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
SelectManyis to flatten a list of lists. Joining tables doesn't nest lists into lists. What if you change it toSelect? BTW,rseems to be part of the grouping.Selectrather thanSelectMany! Told you I was going code blind!