I am in need to join two data tables and retrieve some columns(which will chosen dynamically) from the joined table. I have used the LINQ query to perform joins but i was not able to select columns columns dynamically.
The code is:
var q = (from pd in tableOne.AsEnumerable()
join od in tableTwo.AsEnumerable() on pd.Field<string>(leftTableColumn) equals od.Field<string>(rightTableColumn)
select new
{
Column1=pd.Field<dynamic>(reuiredColumn1),
Column2=od.Field<dynamic>(requireColumn2)
});
here tableOne and tableTwo are Data Tables. The problem here is I can always able to get only two columns(column1,column2) as per the query.But i am in need to form the select query dynamically based on the user selection.
Can anyone please share any idea regards how to achieve this result?