I want to set the accuracy of all decimal properties (18.6). In EF6, this was pretty simple:
modelBuilder.Properties<decimal>().Configure(x => x.HasPrecision(18, 6));
but I cannot find anything like this in EF Core. Removing the cascade exception convention was not as easy as in EF6, so I found the following workaround:
EF6:
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
EF Core:
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
relationship.DeleteBehavior = DeleteBehavior.Restrict;
and after I read this one , I tried a similar approach:
foreach (var entityType in modelBuilder.Model.GetEntityTypes()
.SelectMany(x => x.GetProperties())
.Where(x => x.ClrType == typeof(decimal)))
{
}
I would like if I were on the right track and how to proceed, or if not, I should start putting data annotations in all properties decimal
.
source
share