I am using Entity Framework 6.1, code first. I am trying to store / retrieve a decimal from SQL Server, but the correct precision is not retrieved. I read from a CSV file, processed the data, and then inserted it into the database.
- Value in the CSV file:
1.1390 - Value when saving as
decimal from import: 1.1390 - The value inserted into the database:
1.139 - Value actually saved / displayed in SSMS:
1.1390 - The value when you manually run the query SQL Profiler commits to extract:
1.1390 - Value Received by EF:
1.1300
Everything works, except for getting the value. I tried the solution given in all other SO posts (below), but this has no effect. What's going on here? How can I get the right value with the right precision?
Estimated Solution:
modelBuilder.Entity<ClassA>().Property(p => p.MyDecimal).HasPrecision(19, 4);
The search method returns a ClassA type with the wrong precision:
_poRepository.Table.FirstOrDefault(p => p.CompNumberA == compNum && p.LineNumber == lineNumber);
Comparison of two decimal values:
import.MyDecimal != dbValue.MyDecimal
ClassA :
public class ClassA {
c # entity-framework
vaindil
source share