c# - Nhibernate use extention functions in Query -


i have written query:

from order in session.query<orm.entities.order>()                                   order.finishable()                                   select order); 

where finishable method containing business logic returns bool.

nhibernate returning system.notsupportedexception: boolean finishable() exception.

the logic in finishable() bit more complex. questions are:

  1. what can allow use of custom functions in queries? have change signature of method?
  2. is idea in way? try rewrite logic work nhibernate. result in duplicating logic somehow. unavoidable in case?
  3. i try fetch data necessary compute finishable() afterwards, first orders , fill them data, , after use function is.

so best solution?

any actual named function write going compiled compiler, , unusable linq query provider.

you need create expression represents operation have.

you want use lambda create expression, don't need inline lambdas, typical. can create method/property/field stores expression wish expose larger scope:

public class order {     //consider renaming appropriate     public static expression<func<order, bool>> finishable     {                 {             //todo change logic in lambda needed             return order => order.status == "finished";         }     } } 

you can write:

var query = session.query<orm.entities.order>()     .where(orm.entities.order.finishable); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -