LINQ To SQL 中使用In

来源:互联网 发布:易连接软件 编辑:程序博客网 时间:2024/05/16 19:24

 

   有讀者來信問及LINQ To SQL中如何使用IN,

 倒讓我發現到我一直都未提到這個用法,^_^|||

用法如下:

 

C#
       var result = from s1 in context.Customers where (new string[]
                      { "UK", "Lisboa" }).Contains(s1.City) select s1;
 
VB.NET
    Dim lists = From s1 In context.Customers Where (New String() {"UK", "Lisboa"}).Contains(s1.City) Select s1
那NOT IN呢?
C#
  var result = from s1 in context.Customers where !(new string[] { "UK", "Lisboa" }).Contains(s1.City) select s1;
VB.NET
      Dim lists = From s1 In context.Customers Where Not (New String() {"UK", "Lisboa"}).Contains(s1.City) Select s1