Ich habe eine Klasse mit dem Namen Product
in Klassenbibliothek Projekt. Ich verwende SubSonic SimpleRepository
, um Objekte zu persistieren. Ich habe eine Methode wie in Product
Klasse folgt:Variable 'x' vom Typ 'Produkt' referenziert vom Geltungsbereich, aber es ist nicht definiert
public static IList<Product> Load(Expression<Func<Product, bool>> expression)
{
var rep=RepoHelper.GetRepo("ConStr");
var products = rep.Find(expression);
return products.ToList();
}
ich diese Funktion wie folgt aufrufen:
private void BindData()
{
var list = Product.Load(x => x.Active);//Active is of type bool
rptrItems.DataSource = list;
rptrItems.DataBind();
}
Aufruf Load
aus BindData
wirft die Ausnahme:
variable 'x' of type 'Product' referenced from scope '', but it is not defined
Wie kann Ich löse das auf.
EDIT: - indem sie durch SubSonic
Code Schritt fand ich, dass der Fehler durch diese Funktion
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);
}
Sieht aus wie ein Fehler in SubSonic. (@Kobi: Nr.) – Timwi
@Timwi jede Umgehungslösung das? – TheVillageIdiot