Linq to DataSet Left Join
Hello
Once again with a linq query problem...
The query works but only retrieve the joined rows, i want to retrieve all rows in the first datatable.
My current query:
vb.net Code:
Dim q = From regE In (From registoE In _dtRegistosAEnviar.AsEnumerable
Group registoE By colaborador = registoE.Field(Of String)("Colaborador") Into grupoE = Group
Select New With {
.Colaborador = colaborador,
.Seg = grupoE.Sum(Function(registoE) registoE.Field(Of Decimal)("Seg"))
}).AsEnumerable,
regS In (From registoS In _dtRegistosEnviados.AsEnumerable
Group registoS By colaborador = registoS.Field(Of String)("Colaborador") Into grupoS = Group
Select New With {
.Colaborador = colaborador,
.Seg = grupoS.Sum(Function(registoS) registoS.Field(Of Decimal)("Seg"))
}).AsEnumerable
Where (regE.Colaborador = regS.Colaborador)
Re: Linq to DataSet Left Join
Re: Linq to DataSet Left Join
Thanks JMC
But that doesn't work, i already tested two different ways, the first one, that was similar to that one in Codeguru, the INTO clause after the Equals isn't recognized, i used this in here. Then i looked to another page at MSDN doesn't know which one and change the query to the one that i wrote...
Re: Linq to DataSet Left Join
Hmmm... I didn't, and don't right now, have the time to experiment and I've never done it before myself. I'll try later in the day if you still need it then.
Re: Linq to DataSet Left Join
Thanks but the join problem it's kind of solved.
Now i have other problem, and i don't know what to do. In the selected rows of the join, if i put only the fields of the left table, the query works fine, but if i put the row that i need from the right table, when the table don't have values for the matching it raises a nullexception.
I already tried to check if the value is nothing, but without luck.
Here's the code:
vb.net Code:
Dim query = From regE In (From registoE In _dtRegistosAEnviar.AsEnumerable
Group registoE By colaborador = registoE.Field(Of String)("Colaborador") Into grupoE = Group
Select New With {
.Colaborador = colaborador,
.Seg = grupoE.Sum(Function(registoE) registoE.Field(Of Decimal)("Seg"))
}).AsEnumerable
Group Join regS In (From registoS In _dtRegistosEnviados.AsEnumerable
Group registoS By colaborador = registoS.Field(Of String)("Colaborador") Into grupoS = Group
Select New With {
.ColaboradorS = colaborador,
.SegS = grupoS.Sum(Function(registoS) registoS.Field(Of Decimal?)("Seg"))
}).AsEnumerable
On regE.Colaborador Equals regS.ColaboradorS Into juncao = Group
From ele In juncao.DefaultIfEmpty
Select New With {
.Colaborador = regE.Colaborador,
.HorasPorLancar = regE.Seg,
.TheErrorColum= ele.SegS <<<<<<<<< ERROR >>>>>>>
}
If i remove the line that throws the exception it works fine and i have all the values, but when i put this error column it throws the exception.
I already tried this
vb.net Code:
IIf(ele.SegS Is Nothing, 0, ele.SegS)
and this
vb.net Code:
If(ele.SegS Is Nothing, 0, ele.SegS)
and this
vb.net Code:
IIf(IsDBNull(ele.SegS), 0, ele.SegS)
and this
vb.net Code:
If(IsDBNull(ele.SegS), 0, ele.SegS)