Join two tables using linq, and fill a Dictionary of them

后端 未结 3 888
情深已故
情深已故 2021-01-06 05:17

I\'ve been searching how to join two tables (Data and DataValues, one to many) and fill a dictionary of type .

The records of Data(s) might be thousands (e.g. 500,00

3条回答
  •  春和景丽
    2021-01-06 06:00

    You don't need foreach loop. Try something like this in general:

    var columns = dt.Columns.Cast();
    dt.AsEnumerable().Select(dataRow => columns.Select(column => 
                         new { Column = column.ColumnName, Value = dataRow[column] })
                     .ToDictionary(data => data.Column, data => data.Value));
    

    Also, consider reading this: http://blogs.teamb.com/craigstuntz/2010/01/13/38525/

提交回复
热议问题