0
votes

I have an exiting database with couple of float/double fields, I chose to use EF4.1 for my DAL/ORM, but I am having problems when reading/saving data to his type of fields. There is no model, just using model builder to configure the entities.

First there was a rounding problem, I think typical of floating point math, so because all of the precision were already set as 2 decimals, I switched to using decimal type on the c# (EF) side, but now when I am trying to get an entity, I get an exception saying I am in trouble.

The 'xxxkg' property on 'YYY' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Decimal'.

xxxkg is float null on the database, and the value is 10 in the specific case, and in the class it is

public decimal? xxxkg { get; set; }

The question is how to deal with dbtype float/double variables with EF4 (poco)?

1

1 Answers

0
votes

You cannot define your property as decimal if it is double in database. EF does not type conversion (and doesn't allow you defining your own) and double value cannot be assigned to decimal variable so populating your class from read record will fail. You must use double.