I'm using Entity Framework v6.1.3 (code first) and ASP.NET MVC v5.2.3
I know I can use DisplayFormatAttribute in a decimal datatype like this
[DisplayFormat(ApplyFormatInEditMode = false, DataFormatString = "{0:N2}")]
public decimal Foo { get; set; }
Now what I need is to apply this attribute automatically to every decimal in each entity.
Is this possible?
I had a similar requirement that every decimal must have a precision of 20,8 and I solved this using this code
public class EntitiesContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Set all decimals data types by default as Decimal(20, 8)
modelBuilder.Properties<decimal>().Configure(c => c.HasPrecision(20, 8));
}
}
So I wonder if is it possible to assign automatically the DisplayFormatAttribute.