LINQ find records without connection

I have the following LINQ query:

vm.Ter = (from tr in DataContext.Terr_Rp join dm in DataContext.Dt_Mrs on tr.T_ID equals dm.D_ID + "00" select tr).ToList(); 

I need to find those that do not have a match. This means that there is no connection. I tried unequal, but C # has problems with it.

+4
source share
2 answers

Using !Any() should do the trick.

 vm.Ter = (from tr in DataContext.Terr_Rp where !DataContext.Dt_Mrs.Any(dm => tr.T_ID == dm.D_ID + "00") select tr).ToList(); 
+5
source
 var list1 = new List<int>{1,2,3,4,5,6}; var list2 = new List<int>{5,6,7,8,9,10}; var result = from l1 in list1 where !list2.Contains(l1) select l1; result: {1,2,3,4} 
0
source

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


All Articles