How to change the precision and the scale of decimal globally through code first?

c# ef-code-first entity-framework entity-framework-6 linq

Question

This is the answer: EF Code First decimal accuracy and scale

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

I have the ability to modify the scale and decimal precision for a given attribute in a certain entity.


Because I have so many decimal characteristics in various entities, I'm wondering how to convert them all at once to a specified accuracy and scale.

1
2
5/23/2017 12:00:46 PM

Accepted Answer

The DbModelBuilder.Properties technique may be used:

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

as in this:

modelBuilder.Properties<decimal>().Configure(p => p.HasPrecision(12, 10));
4
8/20/2016 5:18:14 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow