Entityframework model first decimal precision

ef-model-first entity-framework entity-framework-6


Entityframework 6 is what I'm using, model first. I used decimal as my datatype in the diagram. When I save decimal values, the decimals are dropped and the database only stores whole integers.

My initial thought was to verify the precision, but when I opened the properties box in the model first diagram designer, the scale and precision dropdowns only had the option "None."

How do I make EF save my decimal points? Is there a precision problem? In that scenario, how can I set the precision?

6/20/2014 4:26:16 PM

Accepted Answer

Okay, I feel a little foolish for not noticing this sooner, but there is an easy cure.

Precision and scale are both drop-down menus in the properties box for the column in the edmx designer, but you can still enter in the fields. I simply entered 2 for the scale and pushed enter, and it worked.

I'm not sure why they set it up as a drop-down menu if they don't provide you any pre-defined values and demand that you fill it in.

6/20/2014 6:18:10 PM

Popular Answer

Also to be noted is the potential difficulty with Entity Framework's "Update Model from Database" capability. I updated a few database fields in my example from 2 decimal precision to 4 decimal precision, but when I checked the field's scale property in the table's property window in the.edmx diagram, it had not changed. I tried again after manually changing the scale from 2 to 4, but the data was still being saved with 2 decimal places. After restarting Visual Studio, nothing changed. I attempted Update Model from Database again, and this time it was successful.

The database visual modeler in Visual Studio hasn't been kind to me very often. This is simply one of the reasons why I like to control everything through code. Model updates that are thorough and precise are never commonplace.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow