question

TZacks-2728 avatar image
0 Votes"
TZacks-2728 asked TimonYang-MSFT answered

How to convert this datatable join into regualr join

See the code

 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()));

code taken from https://www.c-sharpcorner.com/blogs/update-datatable-using-linq1


I do not understand the above join code. So tell me how to convert the above join to similar one as below example join and update data

 result1 = (from bclist in BogeyConfigList.AsParallel() 
     from prd in PeriodList.AsParallel()   
     from brk in BrkHistData.AsParallel() 
     select new BogeyData
     {
     Broker = brk.HistBroker,
     Select = brk.BrkHistSelect,
     Section = bclist.Section,
     LineItem = bclist.Li,
     }).ToList();

please convert the code. thanks

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TimonYang-MSFT avatar image
1 Vote"
TimonYang-MSFT answered

Please try the following linq statement, it should be equivalent to the current code.

             var re = (from person in _dtMaster.AsEnumerable()
                       join pet in _dtChild.AsEnumerable() on person["id"] equals pet["id"]
                       select new
                       { person, pet }).ToList();
             foreach (var item in re)
             {
                 item.person.SetField("Discription", item.pet[2].ToString());
             }

If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
1 Vote"
karenpayneoregon answered

The following is easy enough to follow with inner and outer joins.

https://www.c-sharpcorner.com/blogs/inner-join-and-outer-join-in-datatable-using-linq


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.