public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None) { var colAttr = (ColumnAttribute)prop.GetCustomAttributes(typeof(ColumnAttribute), true).FirstOrDefault(); _prop = prop; Name = colAttr == null ? prop.Name : colAttr.Name; //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType; Collation = Orm.Collation(prop); IsPK = Orm.IsPK(prop) || (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) && string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0); bool isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK)); IsAutoGuid = isAuto && ColumnType == typeof(Guid); IsAutoInc = isAuto && !IsAutoGuid; Indices = Orm.GetIndices(prop); if (!Indices.Any() && !IsPK && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) && Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase) ) { Indices = new[] { new IndexedAttribute() }; } IsNullable = !IsPK; MaxStringLength = Orm.MaxStringLength(prop); }
public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None, IColumnInformationProvider infoProvider = null) { if (infoProvider == null) { infoProvider = new DefaultColumnInformationProvider(); } _prop = prop; Name = infoProvider.GetColumnName(prop); //If this type is Nullable<T> then Nullable.GetUnderlyingType returns the T, otherwise it returns null, so get the actual type instead ColumnType = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType; Collation = Orm.Collation(prop); IsPK = Orm.IsPK(prop) || (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) && string.Compare(prop.Name, Orm.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0); var isAuto = Orm.IsAutoInc(prop) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK)); IsAutoGuid = isAuto && ColumnType == typeof(Guid); IsAutoInc = isAuto && !IsAutoGuid; DefaultValue = Orm.GetDefaultValue(prop); Indices = Orm.GetIndices(prop); if (!Indices.Any() && !IsPK && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) && Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase)) { Indices = new[] { new IndexedAttribute() }; } IsNullable = !(IsPK || Orm.IsMarkedNotNull(prop)); MaxStringLength = Orm.MaxStringLength(prop); }