I am trying to join two data tables based on ID
column but my problem is one of my data table has variable column count depending on request.
First DataTable (This will always have fixed number of columns)-
ID Int,
firstCol Varchar,
SecondCol Varchar
Second DataTable (This can have variable number of columns depending of request) -
ID Int,
dynamicCol1 varchar,
dynamicCol2 varchar,
dynamicCol3 varchar,
// More or less columns depending on request
Now I want to join these two data Tables which should return me result if possible in the form of dataTable consisting all the columns from both tables.
Resultant Table or enumerable datarow list -
ID Int,
firstCol Varchar,
SecondCol Varchar
dynamicCol1 varchar,
dynamicCol2 varchar,
dynamicCol3 varchar,
// More or less columns depending on request
I tried following linq
it joins these tables but I am not sure how to select all the columns from both tables. I tried following linq,
//submissionData - First datatable
//responseData - Second datatable
Dim resultData = From subData In submissionData.AsEnumerable()
Join resData In responseData.AsEnumerable()
On subData.Field(Of Integer)("ID") Equals resData.Field(Of Integer)("ID")
Select result = {resData, subData}
// Understandably this returns list of set of data rows separately. Which I have to flatten using more code.
My question is what do I select
to get result I want,
Select result = {// what should do here to get the desired result instead of getting my result which needs more code to flatten it out}
I can off course write more code and flatten the result which I am getting now but I was wondering is there any better way to get this result as I dont have enough knowledge of Linq. Any pointers/help would be really appreciated. C# based help will also work. In case of any confusion query please feel free to comment. Thanks in advance.