Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

938
Views
Entity Framework Core: configuración de la precisión decimal y la escala en todas las propiedades decimales

Quiero establecer la precisión de todas las propiedades decimales en (18,6). En EF6 esto fue bastante fácil:

 modelBuilder.Properties<decimal>().Configure(x => x.HasPrecision(18, 6));

pero parece que no puedo encontrar nada similar a esto en EF Core. Eliminar la convención de eliminación en cascada no fue tan simple como en EF6, así que encontré la siguiente solución:

EF6:

 modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>(); modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

Núcleo EF:

 foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys())) relationship.DeleteBehavior = DeleteBehavior.Restrict;

y después de leer esto , probé un enfoque similar:

 foreach (var entityType in modelBuilder.Model.GetEntityTypes() .SelectMany(x => x.GetProperties()) .Where(x => x.ClrType == typeof(decimal))) { // what to do here? }

Me gustaría si estoy en el camino correcto y cómo continuar, o si no, debería comenzar a poner anotaciones de datos en todas las propiedades decimal .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Te acercaste. Aquí está el código.

 foreach (var property in modelBuilder.Model.GetEntityTypes() .SelectMany(t => t.GetProperties()) .Where(p => p.ClrType == typeof(decimal) || p.ClrType == typeof(decimal?))) { // EF Core 1 & 2 property.Relational().ColumnType = "decimal(18, 6)"; // EF Core 3 //property.SetColumnType("decimal(18, 6)"); // EF Core 5 //property.SetPrecision(18); //property.SetScale(6); }
 // EF Core 6 protected override void ConfigureConventions( ModelConfigurationBuilder configurationBuilder) { configurationBuilder.Properties<decimal>() .HavePrecision(18, 6); }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!