加入数据表支持左右全 但是我找不到任何一般的解决方案,假设这种情况下要联接两个表:DT1 Left Join DT2 On DT1.Id != DT2.Id或DT1 Right Join DT2 On ((DT1.Age + 2) = DT2.Age) OR (DT1.BirthDate > DT2.BirthDate))如您所见,我需要一些通用的解决方案来在两个具有复杂Where子句的数据表之间动态联接,我有一个数据结构来支持复杂的Where子句,但是如何动态联接呢?有什么建议吗?解决方案如果在3.0或更高版本上运行,则可以在此处使用LINQ.我知道这是不正确的,只是给您一个想法.您需要在此代码中进行一些搜索.只是寻求帮助.如果未找到匹配的记录,则已将DefaultIfEmpty应用于要从其返回null的表. var dt = (from dt1 in DT1.AsEnumerable() from dt2 in DT2.AsEnumerable().Where(dt1.Id==dt2.Id).DefaultIfEmpty() select new { dt1.Column }).CopyToDataTable();I search a lot about dynamic join on DataTables,I found: Inner Join With Dynamic Columns Inner Join On DataTables Dynamic Linq To Dynamic JoinJoin DataTable Support Left-Right-FullBut I can't find any general solution, assume this scenario for join two tables:DT1 Left Join DT2 On DT1.Id != DT2.IdOrDT1 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? 解决方案 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(); 这篇关于DataTables动态联接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-16 16:53