我有一个类,它有几个浮点属性
class BodyParameters
{
public float Weight { get; set; }
public float Height { get; set; }
public float ThighLength { get; set; }
}
如何为我的"BodyParameters"实体类中的浮点型所有属性设置相同的精度和小数位数?
我当前的解决方案是在模型构建器中逐个设置它们,这可能需要大量手动工作,因为实体类可以具有多达40个属性:
builder.Entity<BodyParameters>(entity =>
{
entity.Property(entity => entity.Height)
.HasPrecision(5, 2);
entity.Property(entity => entity.Weight)
.HasPrecision(5, 2);
entity.Property(entity => entity.ThighLength)
.HasPrecision(5, 2);
});
我也发现了类似的问题:Entity Framework Core - setting the decimal precision and scale to all decimal properties个.
但我只需要将精度设置为在我的entity class中浮动属性,而不是我的DbContext中,