asp.net web api - How to transform OData filter to a LINQ expression? -
i'm trying extract filter expression odataqueryoptions
can use in business logic class.
public pageresult<poco> get(odataqueryoptions odataqueryoptions) { expression<func<poco, bool>> myexpression = ... // do here? var result = _mybusinesslogic.search(myexpression); return new pageresult<poco>(result, null, null); }
i took @ blog describing translating query hql here , think (at least hope) that's overkill i'm trying do.
i need filter expression in expression<func<poco, bool>>
form. tried playing applyto()
can't quite it. appreciated.
we have filterbinder class suits needs internal unfortunately. nevertheless simple trick hold of $filter expression,
public static class odataqueryoptionsextensions { public static expression toexpression<telement>(this filterqueryoption filter) { iqueryable queryable = enumerable.empty<telement>().asqueryable(); queryable = filter.applyto(queryable, new odataquerysettings()); return queryable.expression; } }
in case, can do,
public pageresult<poco> get(odataqueryoptions odataqueryoptions) { expression<func<poco, bool>> myexpression = odataqueryoptions.filter.toexpression<poco>(); var result = _mybusinesslogic.search(myexpression); return new pageresult<poco>(result, null, null); }
notice expression contains looks more this, sotests.customer[].where($it => conditional-expression)
. so, might have extract conditional expression lambda.
Comments
Post a Comment