c# - Create a bool Linq to SQL Expression from an Int Expression -
in linq sql have expression returns int, , want make expression based on expression returns boolean. int can used orderby(score) , boolean can used where(ifscore). i'm unable figure out how use score define ifscore, , appreciate help.
expression<func<model, int>> score = p => (testlist.count() > 0 && p.name.contains(testlist.firstordefault()) ? 1 : 0); expression<func<model, bool>> ifscore = p => //how if score > 2
i'm not sure how play linq sql, can use expression.greaterthan create appropriate binary-expression, , it's matter of creating right expression<tdelegate> that.
var body = expression.greaterthan(score.body, expression.constant(2)); var ifscore = expression.lambda<func<model, bool>>(body, score.parameters); the final expression like:
p => (( testlist.count() > 0 && p.name.contains(testlist.firstordefault()) ? 1 : 0 ) > 2 of course, little nonsensical because can never true. sure intended this? perhaps want compare 1 or 0 equality instead?
Comments
Post a Comment