How to convert this datatable join into regualr join

T.Zacks 3,996 Reputation points
2021-06-07T17:33:10.233+00:00

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

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

Accepted answer
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-06-08T06:32:46.817+00:00

    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.

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-06-07T19:58:41.777+00:00

    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

    1 person found this answer helpful.
    0 comments No comments

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.