【问题标题】:Setting up precision on columns. Entity Framework CF在列上设置精度。实体框架 CF
【发布时间】:2012-02-29 16:42:19
【问题描述】:

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

【问题讨论】:

  • 标题和问题文本非常不同且不相关,缺少aspnet和aspnet-mvc标签...

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


【解决方案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?

祝你好运!

【讨论】:

    猜你喜欢
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    相关资源
    最近更新 更多