LinqTOEntities差异beteen存在并包含 [英] LinqTOEntities difference beteen Exists and contains
本文介绍了LinqTOEntities差异beteen存在并包含的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在contains
上使用exists
var s = new int[] { 1, 2, 3, 4, 5 };
dbset.where(x => s.contains(x.id);
或
var s = new int[] { 1, 2, 3, 4, 5 };
dbset.Where(x => s.Exists(y => x.id));
推荐答案
- 存在是
List<T>
的方法,没有数组或IEnumerable<T>
扩展名上的此类方法. - 此方法用法的正确语法为
x => s.Exists(y => y == x.id)
(您应传递谓词,即返回布尔值的方法) - 区别是-Linq to Entities支持
Contains
,不支持Exists
.
- Exists is a method of
List<T>
, there is no such method on array orIEnumerable<T>
extensions. - 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) - The difference is -
Contains
supported by Linq to Entities,Exists
is not supported.
这篇关于LinqTOEntities差异beteen存在并包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文