2011-07-29 1 views
0

Linq를 사용하여 컬렉션에서 GroupBy를 수행 한 후 개체 컬렉션을 반환하는 데 어려움을 겪고 있습니다.Linq Group 다른 그룹으로 그룹화 된 개체 컬렉션을 반환하는 방법은 무엇입니까?

EF 4.1에서 뷰를 호출 할 때 반환되는 CurrentSegmentGroupDetail 개체의 컬렉션이 있습니다. 람다 표현식을 사용하여 CurrentSegmentGroupDetail 객체를 SegmentGroup 속성으로 그룹화합니다. 내가 얻은 결과는 CurrentSegmentGroupDetail 객체를 포함하는 SegmetGroups의 목록입니다. 내가 겪고있는 문제는 그룹화 된 결과 집합을 다시 List 유형으로 반환하려는 것입니다.

"암시 적으로 변환 할 수 없습니다 유형 : 나는 시도하고 내 목록의 객체로 결과 집합을 통과 할 때 여기에

public List<CurrentSegmentGroupDetail> GetSegmentGroupsForReconciliation() 
    { 
     using (var context = new PricingContext()) 
     { 
      var segmentGroups = 
       context.CurrentSegmentGroupDetails.GroupBy(s => s.SegmentGroup).Select(y => y); 

      return segmentGroups; 
     } 
    } 

내가지고있어 예외 : 여기

내가 지금까지 가지고있는 코드입니다 'System.Linq.IQueryable>' 'System.Collections.Generic.List'로.

나는 크게 여기에 대한 도움을 주셔서 감사합니다.

답변

1

ToList()를

return segmentGroups.ToList(); 
관련 문제