In the Join below, I'd like to use multiple fields to do the join rather than just one field.
var join = group.Join(procSums, g => g.DeptID, ps => ps.key.deptID, (g, ps)...
All examples Ive found use the query style to do this and I can't translate it.
Thanks!
In LINQ, an inner join is used to serve a result which contains only those elements from the first data source that appears only one time in the second data source. And if an element of the first data source does not have matching elements, then it will not appear in the result data set.
In a LINQ query expression, join operations are performed on object collections. Object collections cannot be "joined" in exactly the same way as two relational tables. In LINQ, explicit join clauses are only required when two source sequences are not tied by any relationship.
You just have to Join based on new anonymous objects:
// ClasID is a placeholder, it could be any property you'd like
var join = group.Join(procSums,
g => new { g.DeptID, g.UnitLoc, g.Proc },
ps => new
{
DeptID = ps.key.deptID,
UnitLoc = ps.key.unitLoc,
Proc = ps.key.procName
},
(g, ps) => new { g, ps });
You need to pass lambda expressions that create anonymous types with the fields.
For example:
group.Join(procSums, g => new { g.DeptID, g.OtherField }, ps => new { ps.key.deptID, ps.key.OtherField }, ...)
The anonymous types must match exactly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With