Wednesday, 15 May 2013

entity framework - .NET EF - dividing a byte field results an int instead of double -



entity framework - .NET EF - dividing a byte field results an int instead of double -

interesting one.

see next entity framework query:

entities.select(x => new { x.experiencemonths, calculated = (x.experiencemonths > 0 ? x.experiencemonths / 12 : 0) })

the column experiencemonths tinyint in database, means it's byte in ef model.

i'd expect calculated column double (float), since we're dividing number, no matter ends int , decimal portion of result removed, ex 3.7 ends 3.

is there way forcefulness ef convert result somehow double? adding (double) cast before partition look breaks @ runtime.

using ef5.

thanks!

i tried:

calculated = (x.experiencemonths > 0 ? ((double)x.experiencemonths) / 12 : 0)

and worked fine

.net entity-framework

No comments:

Post a Comment