You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
1021 B
26 lines
1021 B
using System;
|
|
using System.Data.Entity.ModelConfiguration.Configuration;
|
|
using System.Data.Entity.ModelConfiguration.Conventions;
|
|
|
|
namespace ChangKeTec.Wms.Models
|
|
{
|
|
/// <summary>
|
|
/// 用于modelBuilder全局设置自定义精度属性
|
|
/// </summary>
|
|
public class DecimalPrecisionAttributeConvention
|
|
: PrimitivePropertyAttributeConfigurationConvention<DecimalPrecisionAttribute>
|
|
{
|
|
public override void Apply(ConventionPrimitivePropertyConfiguration configuration, DecimalPrecisionAttribute attribute)
|
|
{
|
|
if (attribute.Precision < 1 || attribute.Precision > 38)
|
|
{
|
|
throw new InvalidOperationException("Precision must be between 1 and 38.");
|
|
}
|
|
if (attribute.Scale > attribute.Precision)
|
|
{
|
|
throw new InvalidOperationException("Scale must be between 0 and the Precision value.");
|
|
}
|
|
configuration.HasPrecision(attribute.Precision, attribute.Scale);
|
|
}
|
|
}
|
|
}
|