我有一个名为的班级 Product
在类库项目中。我在用 SubSonic SimpleRepository
坚持对象。我有一个方法如下 Product
类:
public static IList<Product> Load(Expression<Func<Product, bool>> expression)
{
var rep=RepoHelper.GetRepo("ConStr");
var products = rep.Find(expression);
return products.ToList();
}
我正在调用这个函数:
private void BindData()
{
var list = Product.Load(x => x.Active);//Active is of type bool
rptrItems.DataSource = list;
rptrItems.DataBind();
}
调用 Load
从 BindData
抛出异常:
variable 'x' of type 'Product' referenced from scope '', but it is not defined
我该如何解决这个问题。
编辑: - 通过踩踏 SubSonic
代码我发现此函数抛出了错误
private static Expression Evaluate(Expression e)
{
if(e.NodeType == ExpressionType.Constant)
return e;
Type type = e.Type;
if(type.IsValueType)
e = Expression.Convert(e, typeof(object));
Expression<Func<object>> lambda = Expression.Lambda<Func<object>>(e);
Func<object> fn = lambda.Compile(); //THIS THROWS EXCEPTION
return Expression.Constant(fn(), type);
}