/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { bool result = value != null && !string.IsNullOrEmpty(value.ToString()); if (!result && string.IsNullOrEmpty(Message)) { Message = string.Format("{0}成员值不能为空!", pm.ColumnName); } return(result); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { string data = Convert.ToString(value); if (System.Text.RegularExpressions.Regex.Match( data, Regex, RegexOptions.IgnoreCase).Length == 0) { return(false); } } return(true); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { string data = Convert.ToString(value); if (MinLength != null && MinLength > data.Length) { return(false); } if (MaxLength != null && data.Length > MaxLength) { return(false); } } return(true); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value == null) { return(true); } if (string.IsNullOrEmpty((string)value)) { return(true); } string sql = "select {0} from {1} where {0}=@p1"; Command cmd = new Command(string.Format(sql, pm.ColumnName, pm.OM.Table)); cmd.AddParameter("p1", value); object result = cc.ExecuteScalar(cmd); return(result == null || result == DBNull.Value); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected override bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { if (value != null && !string.IsNullOrEmpty(value.ToString())) { DateTime data = Convert.ToDateTime(value); if (MinValue != null) { if (MinValue > data) { return(false); } } if (MaxValue != null) { if (data > MaxValue) { return(false); } } } return(true); }
/// <summary> /// 验证处理过程,派生类重写实现具体的验证规则 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> protected abstract bool OnValidating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc);
/// <summary> /// 验证实体属性值 /// </summary> /// <param name="value">属性值</param> /// <param name="source">属性所属对象</param> /// <param name="pm">属性映射描述</param> /// <param name="cc">数据库上下文</param> /// <returns>bool</returns> public bool Validating(object value, object source, Mappings.PropertyMapper pm, IConnectinContext cc) { return(OnValidating(value, source, pm, cc)); }