I have a linq statements that takes two datatables and joins them together on the id column of each table. My issue is that sometimes the value that I am joining is in a different column in the datatable and I would like to be able to have the statement as is and to look at the other column as well:
Existing:
Datatable1.AsEnumerable()
.Join(Datatable2.AsEnumerable(),
dt1Row => Datatable1.Field<string>(rowid),
dt2Row=> Datatable2.Field<string>(rowid),
(dt1Row , dt2Row) => new { dt1Row , dt2Row}).ToList()
.ForEach(o => {
o.dt1Row.SetField(o.dt1Row.Table.Columns["name"].Ordinal, o.dt2Row.Field<string>("name1"));
});
Datatable1.AsEnumerable()
.Join(Datatable2.AsEnumerable(),
//Trying to work out?
( dt1Row => Datatable1.Field<string>("rowid"),
dt2Row=> Datatable2.Field<string>("rowid"))
|| ( dt1Row => Datatable1.Field<string>("rowid"),
dt2Row=> Datatable2.Field<string>("name")),
(dt1Row , dt2Row) => new { dt1Row , dt2Row}).ToList()
.ForEach(o => {
o.dt1Row.SetField(o.dt1Row.Table.Columns["name"].Ordinal, o.dt2Row.Field<string>("name1"));
});