这个例子是说使用动态查询,查询London的顾客并按ContactName排序,关于ListView控件使用参看MSDN,希望对你有帮助。
ParameterExpression param = Expression.Parameter(typeof(Customer), "c");
Expression left = Expression.Property(param, typeof
(Customer).GetProperty("City"));
Expression right = Expression.Constant("London");
Expression filter = Expression.Equal(left, right);
Expression pred = Expression.Lambda(filter, param);
IQueryable custs = db.Customers;
Expression expr = Expression.Call(typeof(Queryable), "Where",
new Type[] { typeof(Customer) }, Expression.Constant(custs), pred);
expr = Expression.Call(typeof(Queryable), "OrderBy",
new Type[] { typeof(Customer), typeof(string) }, custs.Expression,
Expression.Lambda(Expression.Property(param, "ContactName"), param));
IQueryable<Customer> query = db.Customers.AsQueryable().
Provider.CreateQuery<Customer>(expr);