日期:2014-05-17 浏览次数:20937 次
class A
{
public int ID { get; set; }
public string Name { get; set; }
}
class Program
{
static void Main(string[] args)
{
var data = Enumerable.Repeat(0, 6).Select((x, i) => new A { ID = i / 2, Name = ((char)(i / 2 + 65)).ToString() });
Expression<Func<A, bool>> query1 = x => x.ID == 1;
Expression<Func<A, bool>> query2 = x => x.Name == "A";
var query = data.Where(Expression.Lambda(Expression.AndAlso((query1 as LambdaExpression).Body, (query2 as LambdaExpression).Body), (query1 as LambdaExpression).Parameters).Compile() as Func<A, bool>);
foreach (var item in query)
Console.WriteLine("{0} {1}", item.ID, item.Name);
}
}