2

According to this answer:Decimal precision and scale in EF Code First

modelBuilder.Entity<Class>().Property(object => object.property).HasPrecision(12, 10);

I can change the decimal precision and scale for specific property in specific entity .


But i wonder how to change it globally , i mean change all the decimal attributes to specific precision and scale because i have tons of them in different entities.

Community
  • 1
  • 1
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • Did you look at any of the other answers on the linked question? Looks like your question is already answered, set a new convention to be used in all entity models. – Jeff Mercado Aug 20 '16 at 17:24

1 Answers1

4

You can use DbModelBuilder.Properties method:

Begins configuration of a lightweight convention that applies to all primitive properties of the specified type in the model.

like this:

modelBuilder.Properties<decimal>().Configure(p => p.HasPrecision(12, 10));
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343