|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Sep 2004
Messaggi: 3967
|
[C# / .net 4.0]Query dinamiche
Buonasera a tutti.
Sto cercando di implementare un tipo di ricerca dinamica basata sul metodo "Contains": Codice:
public static Expression<Func<T, bool>> DynamicExpression(string propertyName, string filter)
{
//concettualmente
ParameterExpression param = Expression.Parameter(typeof(T), "test");
Expression absProperty = Expression.Property(param, propertyName);
Expression dest = Expression.Constant(filter);
Expression customContains = Expression.Call(absProperty, "Contains", null, dest);
Expression<Func<T, bool>> exp = Expression.Lambda<Func<T, bool>>(customContains, param);
return exp;
}
Codice:
IQueryable result = from r in blah.Where(DynamicExpression("colonna", "valore")
select new
{
//blah
};
Codice:
id colonna colonna2 colonna3 OggettoX(entità che ha una relazione 1-1 o 1-n)...leggasi NavigationProperty Ovviamente quando cerco 'anche' sull'oggettoX giustamente mi dice che non esiste una proprietà associata con quel nome. Per spiegarmi meglio: Codice:
IQueryable result = from r in ctx.Parent.Where(dynamic("category", "blah"))
select new
{
id = r.id,
category = r.Child.category,
columnLol = r.lol
};
Codice:
Instance property 'category' is not defined for type 'Parent'
__________________
Dai wafer di silicio nasce: LoHacker... il primo biscotto Geek
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 11:11.



















