user473104
user473104

Reputation: 311

Setting up precision on columns. Entity Framework CF

How do I specify decimal precision when creating a table column in Code First Entity Framework 4.2?

Upvotes: 0

Views: 356

Answers (1)

lexeme
lexeme

Reputation: 2973

Try using this approach http://geekswithblogs.net/danemorgridge/archive/2010/12/20/ef4-code-first-control-unicode-and-decimal-precision-scale-with.aspx

or

The simplier one:

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

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

Good luck!

Upvotes: 1

Related Questions