How do I left join 2 Data Tables with Join based on multiple columns ?
I am using C#.
Found some solution here: Left Outer on two columns LINQ but getting compile time error.
dtblLeft:
id col1 col2
1 1 S1
2 1 any2
3 2 S2
4 3 S3
5 3 any2
6 5 any2
7 any2
dtblRight:
col1 col2 Result
1 S1 ConfigValue1
2 S2 ConfigValue12
3 S3 ConfigValue13
4 S4 ConfigValue14
Need to do a left join on col1 and col2 values.
Result
id col1 col2 Result
1 1 S1 ConfigValue1
2 1 any2
3 2 S2 ConfigValue2
4 3 S3 ConfigValue3
5 3 any2
6 5 any2
7 any2
The answer suggested How to do joins in LINQ on multiple fields in single join:
var result = from x in entity
join y in entity2
on new { x.field1, x.field2 } equals new { y.field1, y.field2 }
if I use it with DataTable like
var result = from x in entity
join y in entity2
on new { x[field1], x[field2] } equals new { y[field1], y[field2] }
gives compilation error.