0

I search a lot about dynamic join on DataTables, I found:

Inner Join With Dynamic Columns

Inner Join On DataTables

Dynamic Linq To Dynamic Join

Join DataTable Support Left-Right-Full

But I can't find any general solution, assume this scenario for join two tables:

DT1 Left Join DT2 On DT1.Id != DT2.Id

Or

DT1 Right Join DT2 On ((DT1.Age + 2) = DT2.Age) OR (DT1.BirthDate > DT2.BirthDate))

As you see I need some general solution to Dynamically Join between two DataTables with complex Where clause, I have a Data Structure to support complex Where Clauses, But How can I Join Dynamically? any suggestion?

Community
  • 1
  • 1
Saeid Alizade
  • 853
  • 3
  • 9
  • 18
  • Can you show what kind of Linq you already tried? I have tried something similar, so I can probably help you. – Martao Oct 22 '13 at 18:49
  • @Martao I just Know this Type Of Dynamic Linq http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx but this one don't support Dynamic Join – Saeid Alizade Oct 23 '13 at 05:00
  • Agreed, that kind of Dynamic Linq does not really solve your problem. However, I think Bognar's answer might go a long way: http://stackoverflow.com/a/11505884/1606813 – Martao Oct 23 '13 at 16:09

1 Answers1

0

You can use LINQ here, if working on 3.0 or above. I know its not correct but just to give you an idea. You need to do some reasearch in this code. Just for help. You have apply DefaultIfEmpty to the table from which you want to return null in case no matching records found.

var dt = (from dt1  in DT1.AsEnumerable()
          from dt2 in DT2.AsEnumerable().Where(dt1.Id==dt2.Id).DefaultIfEmpty()
          select new {
           dt1.Column
          }).CopyToDataTable();