.net - How To Use C# Linq Predicate with custom Extension Method -


i'm trying write c# extension method, should take predicate , return iqueryable can reuse complicated where predicate

here i'm looking at

    public static ienumerable<t> addcomplexwhere<t>(this ienumerable<t> query, dbcontext context, func<t, string> permissionkeycolumn)     {         return query.where(pp => context.permissions             .where(p => /*permissionkeycolumn in permissions table p.permissionkey  ??????*/)             .where(p => true/* complicated where*/).any());     } 

usage

context.orders.addcomplexwhere(context,o=>o.permissionkey).tolist().. 

this way can keep reusing

to achieve need use

expression<func<t, bool>> 

here example:

public static ienumerable<t> addcomplexwhere<t>(this ienumerable<t> query, dbcontext context, expression<func<t, bool>> expression)     {         return query.where(expression).any());     } 

after modification code should work:

context.orders.addcomplexwhere(context,o=>o.permissionkey == something).tolist().. 

Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -