My current code:
Code: Select all
public static IEnumerable Find(int start, int limit, IEnumerable> filter)
{
var context = new DataContext();
var query = context.OrderViews;
foreach (var tuple in filter)
{
query = query.Where(o => tuple.Item2.Equals(o.GetType().GetProperty(tuple.Item1).GetValue(o, null)));
}
return query.Skip(start).Take(limit);
}
One alternative I've considered was simply creating a where clause for each property in the entity, but that would leave me with a giant set of if statements, which does not really leave me with fuzzy happy feelings.
Another alternative suggested by someone, was to write an extension of sorts to provide the sql for this construction. I'm not really familiar with LinqConnect however and would even know where to begin.
Which would be the best approach to solve this problem? Or is there an other way I'm overlooking?