.net - Linq Expressions: The binary operator Equal is not defined for the types 'MyEnum' and 'System.Enum' -


i convert of data wingrid expression, in order filter output user. have initial collection (of myobjecttype), apply dynamic filters, , obtain filtered collection.

i have problems enumeration - property of myobjecttype.

the enumeration standard enumeration

public enum myenum     b    c end enum 

this how obtain expression:

dim constantexpression constantexpression if typeof value [enum]   constantexpression = expression.constant(value, gettype([enum])) else   constantexpression = expression.constant(value, value.gettype()) end if ... dim expr expression = nothing dim objectpropertyparam = expression.property(objectparam, objectpropertyname)  select case me.operation   case comparisonoperator.contains, comparisonoperator.notcontains   ...   case comparisonoperator.notequal   ...    case comparisonoperator.equal     ' exception here ---------------------------------------     expr = expression.equal(objectpropertyparam, constantexpression)    case comparisonoperator.greatherthanorequal     expr = expression.greaterthanorequal(objectpropertyparam, constantexpression)   case comparisonoperator.lessthanorequal     expr = expression.lessthanorequal(objectpropertyparam, constantexpression) end select 

then following exception occurs:

the binary operator equal not defined types 'myenum' , 'system.enum'.

at system.linq.expressions.expression.getequalitycomparisonoperator(expressiontype binarytype, string opname, expression left, expression right, boolean lifttonull) @ system.linq.expressions.expression.equal(expression left, expression right)

enter image description here

ps.

i observed if

expr = expression.equal(objectpropertyparam,         expression.convert(constantexpression, gettype(myenum))) 

this works, i'd not specity each type of enumerations this, because generic function!?

the problem you're running difference between object.equals , myenum.equals. instead of using expression.equal use expression.call call constant's equals method.

alternatively, if done enums can convert them integers safely (or whatever largest backing type is). don't have hard-code converting specific enum--it work integer-based enum. if it's used things besides enums, using expression.call best.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -