LinqTOEntities difference beteen Exists and contains [closed]

人走茶凉 提交于 2019-12-25 19:42:41

问题


what is the difference between using exists over contains

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));

回答1:


  1. Exists is a method of List<T>, there is no such method on array or IEnumerable<T> extensions.
  2. Correct syntax of usage of this method is x => s.Exists(y => y == x.id) (you should pass predicate, i.e. method which returns boolean)
  3. The difference is - Contains supported by Linq to Entities, Exists is not supported.


来源:https://stackoverflow.com/questions/15481272/linqtoentities-difference-beteen-exists-and-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!