有讀者來信問及LINQ To SQL中如何使用IN,
倒讓我發現到我一直都未提到這個用法,^_^|||
有讀者來信問及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