2012-11-20 5 views
0

다음 코드를 람다 스타일로 변환하려고하는데 성공하지 못했습니다.람다에서 GroupBy를 사용하는 방법?

DiscCurrentLocation[] old = 
    (from v in volumeDC.Volumes 
    join d in volumeDC.Disc_Vs 
    on v.VolumeID equals d.DiscVolumeID 
    group d by new { v.VolumeLibID, d.DiscCurrentLocation } into g 
    where (g.Key.VolumeLibID == libraryId && g.Key.DiscCurrentLocation > -1 
    && g.Count() > 1) 
    select (DiscCurrentLocation)g.Key.DiscCurrentLocation 
).ToArray<DiscCurrentLocation>(); 

누군가 변환 방법을 보여줄 수 있습니까? 감사

답변

3

이 동일해야합니다 :

DiscCurrentLocation[] old = volumeDC.Volumes 
    .Join(volumeDC.Disc_Vs, (v) => v.VolumeID, (d) => d.DiscVolumeID, 
     (v, d) => new { Volume = v, Disc_V = d }) 
    .GroupBy(vd => new { vd.Volume.VolumeLibID, vd.Disc_V.DiscCurrentLocation }) 
    .Where (grp => grp.Key.VolumeLibID == libraryId 
     && grp.Key.DiscCurrentLocation > -1 && grp.Count() > 1) 
    .Select (grp => (DiscCurrentLocation)grp.Key.DiscCurrentLocation) 
    .ToArray<DiscCurrentLocation>() 
; 
+0

그것이 필요한 .Join를 사용할 수 있나요? – Khayralla

관련 문제