Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 243
Robbie Mills Avatar asked Dec 30 '25 03:12

Robbie Mills


1 Answers

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));
}
like image 122
Sajeetharan Avatar answered Jan 01 '26 17:01

Sajeetharan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!