LINQ Left Join On Unequal Strings

I am trying to display rows that do not exist from another table using LINQ. can someone help me?

It uses sql im.

select * from table1 
left join table2
on 
table1.col1 = table2.col1 
and 
table1.col2 = table2.col2
where
table2.col1 is null and table2.col2 is null

Already searched and found some solution. Here is what I have done so far.

from t1 in table1
where 
!(from t2 in table1
  join t3 in table2 on
  new { t2.col1, t2.col2 } 
  equals 
  new { t3.col1, t3.col2 }
  select t2.PK).Contains(t1.PK)
  select t1

The above code works well, but they are just wondering if this is the only solution I can use? I mean, instead of using the JOIN and CONTAINS method, can we use linux linux directly with the where clause?

+3
source share
1 answer

Ok, you could do something like this:

var query = from t1 in table1
            join t2 in table2
            on new { t1.col1, t2.col2} equals { t2.col1, t2.col2 }
            into groups
            where !groups.Any()
            select t1;

groups - t2, "" t1 - , , . , , - Any.

+9

Source: https://habr.com/ru/post/1775358/


All Articles