代码之家  ›  专栏  ›  技术社区  ›  Jens

LINQ to SQL-如何“Where…in…”

  •  0
  • Jens  · 技术社区  · 14 年前

    我想使用linq对结果集进行排序。结果集应该包含在给定数组中也包含其代码的所有项。为了更清楚一点,在sql中应该是:

    select * from tblCodes where CodeSort in (0, 2, 3, 5, 6)
    

    现在我想在林克做同样的事情,但我似乎做不到。。我试过Contains,但是没有得到正确的结果(或者我可能用错了)。我正在用VB写代码。

    1 回复  |  直到 13 年前
        1
  •  3
  •   Community CDub    8 年前

    看看这个

    Dim ids = {1, 2, 3}
    
    Dim query = From item In context.items Where ids.Contains(item.id)item
    

    Linq to SQL in and not in