I have as scenario like this:
One supposed query
var list = (from p in context.table select p.field)
and different "orderby" based on the client choice .
The simple way to do it would look like this:
if (filter.Equals("filter1"))
{
var list = (from p in context.table select p.field).OrderBy(w=> w.filter1);
}
else if (filter.Equals("filter2"))
{
var list = (from p in context.table select p.field).OrderBy(w=> w.filter2);
}
But since there is a lot of filters, it feels like it is an ugly practice to repeat the same query a lot of times just to change the OrderBy
condition, does someone know what would be the best/cleaner approach?