I\'m using now Entity framework- but it\'s a problem \"shared\" between all ORM\'s and even IEnumerable.
Let\'s say I have a method in MVC looks like this:
Try that. This is using reflection and expressions to build the query dynamically. I tested it only with objects.
static IQueryable Filter(IQueryable col, T filter)
{
foreach (var pi in typeof(T).GetProperties())
{
if (pi.GetValue(filter) != null)
{
var param = Expression.Parameter(typeof(T), "t");
var body = Expression.Equal(
Expression.PropertyOrField(param, pi.Name),
Expression.PropertyOrField(Expression.Constant(filter), pi.Name));
var lambda = Expression.Lambda>(body, param);
col = col.Where(lambda);
}
}
return col;
}