How to mention multiple columns in join when using LINQ Method syntax for join

T.Zacks 3,996 Reputation points
2021-06-08T18:36:28.083+00:00

This is sample LINQ method syntax join where single column used in join condition.

DataTable _dtMaster = dt();
_dtMaster.Columns.Add("Discription");
DataTable _dtChild = dttt();
_dtMaster.AsEnumerable().Join(_dtChild.AsEnumerable(), _dtmater => Convert.ToString(_dtmater["id"]),
_dtchild => Convert.ToString(_dtchild["id"]), (_dtmater, _dtchild) => new { _dtmater, _dtchild }).ToList().ForEach(o=>o._dtmater.SetField("Discription",o._dtchild["Discription"].ToString()));

Please tell me how to mention multiple columns in join when i will follow above approach method syntax?

please give me a sample code using above approach kind of LINQ where multiple columns will be used in join.

Thanks

Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-06-08T20:04:57.58+00:00

    You just use an anonymous type.

    from m in _dtMaster
    join c in _dtChild on new { Id = m["id"], SomeValue = m["category"] } equals new { Id = c["masterId"], SomeValue = c["subcategory"] }
    select new { ... }
    
    2 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.