0
votes

I am getting the following error when trying to retrieve float from database:

The 'Hours' property on 'WorkHours' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Single'.

The Hours property in the WorkHours Entity is:

public Single? Hours {get; set;}

Table design type:

Hours Float

When i store a value it stores as a double(16 digits after the point),i believe float is 7 digits after the point.

Any ideas why i am getting that error?

Thanks

MVC3, EF4, Sql Server 8 (2000)

2
I think by default Entity Framework defaults to 2 decimal places precision (it truncates the rest). In Code-First there is a custom mapping method that can be used to set the precision on per property basisIvan Zlatev

2 Answers

1
votes

Maybe this will help:

The 'Hours' property on 'WorkHours' could not be set to a 'Double' value. You must set this property to a non-null value of type 'Single'.

public Single? Hours {get; set;}
             ^
1
votes

I solved this using attribute column ...

    [Column("latitude", TypeName = "float")]