我创建了一个linq,允许从tabRealisation
左连接tabRealisation
Dim query =
(From r In tabRealisation.AsEnumerable
Group Join p In tabPrevision.AsEnumerable
On r.Field(Of Integer)("code_part") Equals p.Field(Of Integer)("code_part")
Into Group
Let p = Group.FirstOrDefault
Select
nom_ville = r.Field(Of String)("nom_ville"),
Designation_part = r.Field(Of String)("Designation_part"),
NbrR = r.Field(Of Integer)("UniteVendu"),
CaR = r.Field(Of Double?)("CAVendu"),
NbrP = p.Field(Of Integer)("UniteVentePrev"),
CaP = p.Field(Of Double?)("CAVentePrev")
).ToList
但我想要的是将此查询转换为Sum("UniteVendu")
,Sum("CAVendu")
,... "code_part"
分组
答案 0 :(得分:0)
试试这个
Dim query =
(From r In tabRealisation.AsEnumerable
Join p In tabPrevision.AsEnumerable
On r.Field(Of Integer)("code_part") Equals p.Field(Of Integer)("code_part")
Select
nom_ville = r.Field(Of String)("nom_ville"),
Designation_part = r.Field(Of String)("Designation_part"),
NbrR = r.Field(Of Integer)("UniteVendu"),
CaR = r.Field(Of Double?)("CAVendu"),
NbrP = p.Field(Of Integer)("UniteVentePrev"),
CaP = p.Field(Of Double?)("CAVentePrev"),
codePart = r.Field(Of Integer)("code_part")
).GroupBy(Function(x) x.codePart).Select(Function(x) New With { _
.codepart = x.Key,
.NbrRSum = x.Sum(Function(y) y.NbrR),
.CarSum = x.Sum(Function(y) y.CaR)
).ToList()