2012-02-08 60 views

回答

1

尝试使用这种方法http://geekswithblogs.net/danemorgridge/archive/2010/12/20/ef4-code-first-control-unicode-and-decimal-precision-scale-with.aspx

的simplier之一:

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); 
    } 
} 

How do I prevent decimal values from being truncated to 2 places on save using the EntityFramework 4.1 CodeFirst?

好运上当受骗!