设置列的精度。实体框架CF.

时间:2012-02-08 08:46:20

标签: .net entity-framework ef-code-first precision

在Code First Entity Framework 4.2中创建表列时,如何指定小数精度?

1 个答案:

答案 0 :(得分:1)

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

更简单的一个:

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?

祝你好运!