【发布时间】:2009-04-08 19:56:58
【问题描述】:
单个和多个列表
考虑以下列表:
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-property 查询我的沙漠数据库,代码会如何?
这是LINQ to SQL query against a list of entities的分支
【问题讨论】:
标签: c# linq linq-to-sql