LinqTOEntities差异beteen存在并包含 [英] LinqTOEntities difference beteen Exists and contains

查看:85
本文介绍了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));

推荐答案

  1. 存在List<T>的方法,没有数组或IEnumerable<T>扩展名上的此类方法.
  2. 此方法用法的正确语法为x => s.Exists(y => y == x.id)(您应传递谓词,即返回布尔值的方法)
  3. 区别是-Linq to Entities支持Contains,不支持Exists.
  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.

这篇关于LinqTOEntities差异beteen存在并包含的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆