c# - Convert to Nullable Decimal in Expression Trees -


my models have nullable decimal types. in expression trees gave me following error:

the binary operator equal not defined types 'system.nullable`1[system.decimal]' , 'system.decimal'

now want convert string decimal? , matter have tried as:

decimal? res = convert.todecimal(mystr); // gives me type system.decimal 

i have looked answers of this, this, this , this. convert type system.decimal , expression trees gave error mentioned above.

i need convert them system.nullable(system.decimal) work me.

how can work out? models generated entity framework edmx cannot change types. have conversion in code.

the normal c# code example you've shown has converted decimal?, using implicit conversion t t? non-nullable value type t.

in expression tree, need use expression.convert perform conversion, e.g.

// assuming beforeconversion expression tree type of // decimal var converted = expression.convert(beforeconversion, typeof(decimal?)); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -