Ho una classe denominata Product
nel progetto di libreria di classi. Sto usando SubSonic SimpleRepository
per persistere oggetti. Ho un metodo come segue Product
classe:variabile "x" di tipo "Prodotto" a cui si fa riferimento dall'ambito, ma non è definita
public static IList<Product> Load(Expression<Func<Product, bool>> expression)
{
var rep=RepoHelper.GetRepo("ConStr");
var products = rep.Find(expression);
return products.ToList();
}
sto chiamando questa funzione come questa:
private void BindData()
{
var list = Product.Load(x => x.Active);//Active is of type bool
rptrItems.DataSource = list;
rptrItems.DataBind();
}
Calling Load
dal BindData
genera l'eccezione:
variable 'x' of type 'Product' referenced from scope '', but it is not defined
Come può Risolvo questo.
EDIT: - facendo un passo attraverso SubSonic
codice che ho trovato che l'errore è gettato da questa funzione
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);
}
Sembra un bug in SubSonic. (@Kobi: No.) – Timwi
@Timwi non ci sono soluzioni alternative? – TheVillageIdiot