Linq 如何在lambda中使用GroupBy?
我正在尝试将以下代码转换为lambda样式,但没有成功Linq 如何在lambda中使用GroupBy?,linq,group-by,Linq,Group By,我正在尝试将以下代码转换为lambda样式,但没有成功 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
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>();
DiscCurrentLocation[]旧=
(从卷中的v开始)C.卷
在volumeDC.Disc\u Vs中加入d
在v.VolumeID上等于d.DiscVolumeID
d组由新的{v.VolumeLibID,d.DiscCurrentLocation}到g
其中(g.Key.VolumeLibID==libraryId&&g.Key.DiscCurrentLocation>-1
&&g.计数()>1)
选择(DiscCurrentLocation)g.Key.DiscCurrentLocation
).ToArray();
有人能告诉我怎么转换吗?
谢谢这应该是相同的:
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>()
;
DiscCurrentLocation[]old=volumeDC.Volumes
.Join(volumeDC.Disc\u Vs,(v)=>v.VolumeID,(d)=>d.DiscVolumeID,
(v,d)=>新的{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)
.选择(grp=>(DiscCurrentLocation)grp.Key.DiscCurrentLocation)
.ToArray()
;
这应该是相同的:
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>()
;
DiscCurrentLocation[]old=volumeDC.Volumes
.Join(volumeDC.Disc\u Vs,(v)=>v.VolumeID,(d)=>d.DiscVolumeID,
(v,d)=>新的{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)
.选择(grp=>(DiscCurrentLocation)grp.Key.DiscCurrentLocation)
.ToArray()
;
是否需要使用.Join?是否需要使用.Join?