我正在尝试连接一些服务器端验证,因此有某种最后一道防线,因此不良数据无法通过。我的一个字段取决于一个布尔值。如果布尔值为真,则 int 值必须为 0。如果为假,则它必须介于 1 和 7 之间。这是我到目前为止所拥有的,但它不起作用。
[ValidApplicationPrimary(ComplianceProfile= NFlagComplianceProfile)]
[Column("APPLICATION_PRIMARY")]
public int ApplicationPrimary { get; set; }
[Required]
[Column("NFLAG_COMPLIANCE_PROFILE")]
public bool NFlagComplianceProfile { get; set; }
public class ValidApplicationPrimary : ValidationAttribute
{
public Boolean ComplianceProfile { get; set; }
public override bool IsValid(object value)
{
if (ComplianceProfile)//If they have a compliance profile the value of Application Primary should be 0
{
if (((Int32)value) == 0)
{
return true;
}
else
{
return false;
}
}
else if (((Int32)value) > 0 && ((Int32)value)<=7) //If Application primary is between 1 and 7 then it is true
{
return true;
}
else //Outside that range its false
return false;
}
我不断收到此错误
Error 3 An object reference is required for the non-static field, method, or property 'EntityFrameworkTable.NFlagComplianceProfile.get'