Possible Duplicate:
Entity Framework Code First: decimal precision
I'm using Linq-to-Entities with the EntityFramework 4.1 Code First system. All of my decimal
properties are being truncated to two decimal places on save. I can examine the object being modified and can see in the debugger that is has the right number of decimal places and I can hard code the value in the database to show that it can accept the right number of decimal places [in this case, decimal(4,3)
]. But when I save the value, it never saves it correctly, but instead truncates decimal
values to two decimal places. I haven't been able to find a class in System.ComponentModel.DataAnnotations
that allows you to specify precision. The class (sanitized), for reference is:
public class Metrics { public decimal? PPM { get; set; } }
public class MyContext : DbContext { public DbSet<Metrics> Metrics { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Metrics>().Property(x => x.PPM).HasPrecision(4, 3); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With