我想将所有十进制属性的精度设置为(18,6).在EF6中,这非常简单:
modelBuilder.Properties<decimal>().Configure(x => x.HasPrecision(18, 6));
Run Code Online (Sandbox Code Playgroud)
但我似乎无法在EF Core中找到类似的东西.删除级联删除约定并不像在EF6中那么简单,因此我找到了以下解决方法:
EF6:
modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
Run Code Online (Sandbox Code Playgroud)
EF核心:
foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
relationship.DeleteBehavior = DeleteBehavior.Restrict;
Run Code Online (Sandbox Code Playgroud)
我看后这个,我尝试了类似的方法:
foreach (var entityType in modelBuilder.Model.GetEntityTypes()
.SelectMany(x => x.GetProperties())
.Where(x => x.ClrType == typeof(decimal)))
{
// what to do here?
}
Run Code Online (Sandbox Code Playgroud)
我想如果我在正确的轨道上以及如何继续,或者如果没有,我应该开始在所有decimal属性上放置数据注释.