c# - Entity Framework Core - setting the decimal precision and scale to all decimal properties -
this question has answer here:
i want set precision of decimal properties (18,6). in ef6 quite easy:
modelbuilder.properties<decimal>().configure(x => x.hasprecision(18, 6));
but can't seem find similar in ef core. removing cascade delete convention wasn't simple in ef6 found 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 read this, tried similar approach:
foreach (var entitytype in modelbuilder.model.getentitytypes() .selectmany(x => x.getproperties()) .where(x => x.clrtype == typeof(decimal))) { // here? }
i if on right track , how continue, or if not, should start putting data annotations on decimal
properties.
you got close. here's code.
foreach (var property in modelbuilder.model.getentitytypes() .selectmany(t => t.getproperties()) .where(p => p.clrtype == typeof(decimal))) { property.relational().columntype = "decimal(18, 6)"; }
Comments
Post a Comment