I have 2 tables, the left table has data like this:
I do a left join with another table with the following expression:
var result = posicion.Join(fact,
p => p.Cod_articulo,
f => f.Cod_articulo,
(p, f) => new { p.Posicion, p.Cant_historico,
p.Cod_articulo, f.Cantidad_facturada });
The problem is that the results don't include some items from the left table as seen below:
As you can see in the result there is no data for position 3, 6 etc. what would be missing from my join?
what would be missing from my join?
Presumably there are no entries in fact
which have the corresponding Cod_articulo
values (e.g. 60155 for posicion 3). Join
in LINQ represents an inner join, where there has to be an entry in both sources in order to create an appropriate result.
If you want a left join, you'd typically use GroupJoin
, so that each element on the "left" side ends up matching a group of entries from the "right" side, where that group may be empty.
See more on this question at Stackoverflow