我有两个数据表 tabRealisation 和 tabPrevision ,我想应用左连接以获得包含所有列的数据表:
这是我试过的:
Dim query1 =
(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") And r.Field(Of Integer)("CodeTypeBien") Equals p.Field(Of Integer)("CodeTypeBien") And r.Field(Of Integer)("month") Equals p.Field(Of Integer)("month") And r.Field(Of String)("TitreFoncier") Equals p.Field(Of String)("TitreFoncier")
Into Group
Let p = Group.FirstOrDefault
Where r.Field(Of Integer)("month") >= 1 And r.Field(Of Integer)("month") <= 12
Select an = r.Field(Of Integer)("year"),
mois = r.Field(Of Integer)("month"),
code_part = r.Field(Of Integer)("code_part"),
TitreFoncier = r.Field(Of String)("TitreFoncier"),
CodeTypeBien = r.Field(Of Integer)("CodeTypeBien"),
UniteStock= r.Field(Of Integer?)("UniteStock"),
CAStock= r.Field(Of Double?)("CAStock"),
UniteVentePrev = If(p Is Nothing, 0, p.Field(Of Integer?)("UniteVentePrev")),
).ToList
现在我想通过“code_part”与左联接进行分组,以获得来自 tabRealisation 和 tabPrevision 的列总和,而不是来自 query1 :