LinqTOEntities difference between exists and contains

what is the difference between using existsovercontains

var s = new int[] { 1, 2, 3, 4, 5 };
dbset.where(x => s.contains(x.id);

or

var s = new int[] { 1, 2, 3, 4, 5 };
dbset.Where(x => s.Exists(y => x.id));
-3
source share
1 answer
  • Exists is a method List<T>; there is no such method in an array or extensions IEnumerable<T>.
  • The correct syntax for using this method is x => s.Exists(y => y == x.id)(you should pass a predicate, i.e. a method that returns a boolean)
  • Difference - Containssupported by Linq to Entities, is Existsnot supported.
+3
source

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


All Articles