【问题标题】:How to use (sql =any) .Any() of linq to entities lambda expressions? [duplicate]如何使用 (sql =any) .Any() of linq to entity lambda 表达式? [复制]
【发布时间】:2016-09-27 06:11:57
【问题描述】:

我想要类似的东西

var o = db.Persons.Where(x=>x.Id in (1, 2));

var o = db.Persons.Where(x=>x.Id =any (1, 2));

获取 id 在 (1, 2) 中的 Persons 列表。

【问题讨论】:

    标签: c# .net entity-framework lambda


    【解决方案1】:
    var o = db.Persons.Where(x=> new[]{1, 2}.Contains(x.Id));
    

    【讨论】:

      【解决方案2】:
      var keys = new List<int>{1,2,3}; //This contains the collection of your Id
      var o = db.Persons.Where(x=>keys.Contains(x.Id));
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-27
        相关资源
        最近更新 更多