using System; namespace Easy4net.CustomAttributes { /// /// 数据库表字段特性 /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public class ColumnAttribute : Attribute { /// /// 字段信息 例如:varchar(255) default '' /// public string TypeInfo { get; set; } /// /// 是否为主键 /// public bool PrimaryKey { get; set; } /// /// 字段名 /// private string _Name = string.Empty; /// /// 是否唯一 /// private bool _IsUnique = false; /// /// 是否允许为空 /// private bool _IsNull = true; /// /// 是否插入到表中 /// private bool _IsInsert = true; /// /// 是否修改到表中 /// private bool _IsUpdate = true; /// /// 在所有操作中是否忽略此字段 /// private bool _Ignore = false; /// /// 表字段名 /// public string Name { get { return _Name; } set { _Name = value; } } /// /// 是否是唯一的,默认为否 /// public bool IsUnique { get { return _IsUnique; } set { _IsUnique = value; } } /// /// 此字段是否允许为空,默认允许为空 /// public bool IsNull { get { return _IsNull; } set { _IsNull = value; } } /// /// 在执行插入操作时此是否插入此字段值,默认为插入 /// public bool IsInsert { get { return _IsInsert; } set { _IsInsert = value; } } /// /// 在执行更新操作时是否更新此字段值,默认为更新 /// public bool IsUpdate { get { return _IsUpdate; } set { _IsUpdate = value; } } /// /// 在执行所有操作时是否忽略此字段,默认不忽略 /// public bool Ignore { get { return _Ignore; } set { _Ignore = value; } } /// /// 创建一个空的字段特性 /// public ColumnAttribute() { } /// /// 创建一个指定字段名的字段特性 /// /// 字段名 public ColumnAttribute(string aName) : this() { this.Name = aName; } /// /// 创建一个制定字段名的字段特性 /// /// 字段名 /// 在执行数据操作时是否忽略此字段 public ColumnAttribute(string aName, bool aIgnore) : this(aName) { this.Ignore = aIgnore; } /// /// 创建一个制定字段名的字段特性 /// /// 字段名 /// 此字段是否参与插入操作 /// 此字段是否参与更新操作 public ColumnAttribute(string aName, bool aInsert, bool aUpdate) : this(aName) { this.IsInsert = aInsert; this.IsUpdate = aUpdate; } } }