简体   繁体   中英

how to equals between multiple table columns in join using Linq

var allData = (from t1 in table1
                join t2 in table2 
                on t1.Column1 equals t2.Column1
                join t3 in table3 
                on t1.Column1.ToString() equals t3.Column1
                join t4 in table4
                on t3.Column1 equals t4.Column1
                join t6 in table4 
                on t1.Column1 equals t6.Column1
                join t5 in table5 
                on     new { X1 = t4.Column1, X2 = t4.Column2 } 
                equals new { X1 = t5.Column1, X2 = t5.Column1 }

i have the same table table4 twice but how can i use equals from different table just like what I did for table5 ?

You can use a Where clause if you don't want to specify table4 twice:

var allData = (from t1 in table1
                join t2 in table2
                on t1.Column1 equals t2.Column1
                join t3 in table3
                on t1.Column1.ToString() equals t3.Column1
                join t4 in table4
                on t3.Column1 equals t4.Column1
                join t5 in table5
                on new { X1 = t4.Column1, X2 = t4.Column2 }
                equals new { X1 = t5.Column1, X2 = t5.Column1 }
                where t1.Column1 == t4.Column1
                select ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM