Merging LINQ result sets with common property at runtime

Suppose I have multiple LINQ result sets that are generated at run-time that have a common key-property but different properties otherwise

Is there anyway, without using Dynamic LINQ (not available on our dev environment), to merge these multiple queries based on the common key-property but without knowing what the properties I'm appending are until run-time?

I also have these same result sets as DataTable objects alternatively - is there perhaps a way to merge these DataTables on the key column and append the additional column values to it?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You could do a simple switch statement with all possibilities written out...
priehlAuthor Commented:
A switch statement isn't ideal because there are several arbitrary permutations and combinations in which the resultsets can be merged based on user-input - would prefer a more generic solution
Fernando SotoRetiredCommented:
Hi priehl;

C# is a strongly typed language and therefor to do what you want will take some work using Reflections to find out the names of the columns and there data types.

seeming you state, "I also have these same result sets as DataTable objects", it would be much easier to use the DataTable.Merge method to combine them. Make sure that in the data table you have the primary key defined in both tables then you can do this:

table1.Merge(table2, false, MissingSchemaAction.Add);

This will merge table2 into table1.

The following link is the documentation for Merge.
DataTable.Merge Method (DataTable, Boolean, MissingSchemaAction) 


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
priehlAuthor Commented:
Thanks, that'll work.

Dynamic LINQ would obviously solve this problem in a few lines.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.