I'm having a difficult time trying to return a collection of objects after I use Linq to do a GroupBy on the collection.
The specifics are, I have a collection of CurrentSegmentGroupDetail objects being returned when I call a view from EF 4.1. Using a Lambda expression, I group the CurrentSegmentGroupDetail object by a SegmentGroup property. The result I get is a list of SegmetGroups that contain CurrentSegmentGroupDetail objects. The problem I'm having is trying to return the grouped result set back to a type of List.
Here is the code I have so far:
public List<CurrentSegmentGroupDetail> GetSegmentGroupsForReconciliation()
{
using (var context = new PricingContext())
{
var segmentGroups =
context.CurrentSegmentGroupDetails.GroupBy(s => s.SegmentGroup).Select(y => y);
return segmentGroups;
}
}
Here is the 开发者_开发技巧exception I'm getting when I try and pass the result set into my List object:
"Cannot implicitly convert type 'System.Linq.IQueryable>' to 'System.Collections.Generic.List'.
I would greatly appreciate any help on this.
ToList()
return segmentGroups.ToList();
精彩评论