單個和多個列表的LINQ to SQL:對列表,數組和對象列表
考慮以下列表的高級查詢:
List<Int32> appleIdentities = new List<int>(new[] { 1, 2, 3 });
List<Int32> chocolateIdentities = new List<int>(new[] { 2, 3, 4 });
List<Int32> icecreamIdentities = new List<int>(new[] { 11, 14, 15, 16 });
使用LINQ to SQL;是否可以寫出一條語句翻譯爲:
SELECT
DesertsID,
DesertsName
FROM
Deserts
WHERE
Deserts.AppleIdentity IN (1, 2, 3) AND
Deserts.ChocolateIdentity IN (2, 3, 4) AND
Deserts.IcecreamIdentity IN (11, 14, 15m 16)
如果是;代碼看起來如果我想查詢我的沙漠數據庫,只需要對appleIdentities
列表進行查詢?
陣列
考慮以下的數組:
Int32[] appleIdentities = new[] {1, 2, 3, 4};
String[] chocolateNames = new[] {"Light", "Dark"};
使用LINQ to SQL;是否可以寫出一條語句翻譯爲:
SELECT
DesertsID,
DesertsName
FROM
Deserts
WHERE
Deserts.AppleIdentity IN (1, 2, 3) AND
Deserts.ChocolateName IN ('Light', 'Dark')
如果是;代碼看起來如果我想查詢我的沙漠數據庫而不是appleIdentities
陣列?對象
列表
考慮以下幾點:
public class Identities
{
public Int32 appleIdentity { get; set; }
public String chokolateName { get; set; }
}
List<Identities> identities = new List<Identities>(new[] {
new Identities { appleIdentity = 1, chokolateName = "Light" },
new Identities { appleIdentity = 2, chokolateName = "Dark" },
});
使用LINQ to SQL;是否可以寫出一條語句翻譯爲:
SELECT
DesertsID,
DesertsName
FROM
Deserts
WHERE
Deserts.AppleIdentity IN (1, 2) AND
Deserts.ChocolateName IN ('Light', 'Dark')
如果是;如果我想查詢我的沙漠數據庫和Identities
對象列表上的appleIdentity
-properties,代碼將如何查看?
這是分叉的LINQ to SQL query against a list of entities
這很有趣,但我每次看這件事。我總是嘗試使用.Any()... – mcfea 2014-06-18 23:54:37