Robbie Mills
Robbie Mills

Reputation: 2945

Entity Framework currency with 3 decimal places

In asp.net 5+ using EF6 with code first, how do I store a decimal value with 3 decimal points?

Ie, my field needs to be able to store 272.724

Currently I have:

[DataType(DataType.Currency)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:c}")]
[DisplayName("Report Fee")]
public decimal ReportFee { get; set; }

I've tried adding:

[Column(TypeName = "decimal(18,3)")]

But I get the error:

The store type 'decimal(18,3)' could not be found in the SqlServer provider manifest

Upvotes: 2

Views: 4069

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

You can try with Custom Conventions. To set decimal precision:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.Properties<decimal>().Configure(config => config.HasPrecision(18, 3));
}

Upvotes: 9

Related Questions