Tuesday, January 21, 2014

Entity Framework Decimal value truncated/rounded

Recently I found while using Entity Framework to insert Decimal values to SQL database, only two decimal places after the point are saved to database. I'm using EF 6. Still not sure why it acts like this. But the code below fixed the problem.

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
            modelBuilder.Entity<Rates>().Property(x => x.TheRate).HasPrecision(19, 9);
}

No comments: