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); var 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 IndexedAttribute[] { new IndexedAttribute() }; } IsNullable = !(IsPK || Orm.IsMarkedNotNull(prop)); MaxStringLength = Orm.MaxStringLength(prop); }
static Dictionary <string, object> RetrieveIndexedProperties(XPClassInfo classInfo, IXPSimpleObject source) { Dictionary <string, object> indexedProperties = new Dictionary <string, object>(); foreach (XPMemberInfo item in classInfo.PersistentProperties) { if (item.HasAttribute(typeof(IndexedAttribute))) { IndexedAttribute attribute = (IndexedAttribute)item.GetAttributeInfo(typeof(IndexedAttribute)); if (attribute.Unique) { indexedProperties.Add(item.Name, item.GetValue(source)); } else { continue; } if (attribute.AdditionalFields != null && attribute.AdditionalFields.Count > 0) { foreach (string fieldName in attribute.AdditionalFields) { indexedProperties.Add(fieldName, classInfo.GetMember(fieldName).GetValue(source)); } } } } return(indexedProperties); }
protected AbstractDirectTableMappingColumn(MemberInfo info, string path, CreateFlags createFlags = CreateFlags.None) : base(info, path, createFlags) { Collation = ORMUtilities.Collation(info); IsPK = ORMUtilities.IsPrimaryKey(info) || (((createFlags & CreateFlags.ImplicitPK) == CreateFlags.ImplicitPK) && string.Compare(info.Name, ORMUtilities.ImplicitPkName, StringComparison.OrdinalIgnoreCase) == 0); var isAuto = ORMUtilities.IsAutoInc(info) || (IsPK && ((createFlags & CreateFlags.AutoIncPK) == CreateFlags.AutoIncPK)); IsAutoGuid = isAuto && TargetType == typeof(Guid); IsAutoInc = isAuto && !IsAutoGuid; if (!Indices.Any() && !IsPK && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) && Name.EndsWith(ORMUtilities.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase) ) { Indices = new IndexedAttribute[] { new IndexedAttribute() }; } IsNullable = !(IsPK || ORMUtilities.IsMarkedNotNull(info)); MaxStringLength = ORMUtilities.MaxStringLength(info); TargetName = info.Name; }
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); IsCK = Orm.IsCK(prop); IsFK = Orm.IsFK(prop); if (IsFK) { ForeignKeyAttribute attr = prop.GetCustomAttribute <ForeignKeyAttribute>(true); TableMapping refTable = new TableMapping(attr.ReferenceTable); string refColumnName = attr.ReferenceColumn ?? this.Name; var refColumns = refTable.Columns.Select(c => c).Where(c => c.Name == refColumnName).ToArray(); if (refColumns.Length > 0) { FK = new ForeignKey(this, attr.ReferenceTable, refColumns[0]); } else { throw new Exception(string.Format("The referenced column \"{0}\" in {1} doesn't exist", refColumnName, this.Name)); } } var 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 IndexedAttribute[] { new IndexedAttribute() }; } IsNullable = !(IsPK || Orm.IsMarkedNotNull(prop)); MaxStringLength = Orm.MaxStringLength(prop); StoreAsText = prop.PropertyType.GetTypeInfo().GetCustomAttribute(typeof(StoreAsTextAttribute), false) != null; }
public Column(PropertyInfo prop, CreateFlags createFlags = CreateFlags.None) { var colAttr = prop.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(ColumnAttribute)); _prop = prop; #if ENABLE_IL2CPP var ca = prop.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute; Name = ca == null ? prop.Name : ca.Name; #else Name = (colAttr != null && colAttr.ConstructorArguments.Count > 0) ? colAttr.ConstructorArguments[0].Value?.ToString() : prop.Name; #endif //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; IsAutomatic = Orm.IsAutomatic(prop); Indices = Orm.GetIndices(prop); if (!Indices.Any() && !IsPK && ((createFlags & CreateFlags.ImplicitIndex) == CreateFlags.ImplicitIndex) && Name.EndsWith(Orm.ImplicitIndexSuffix, StringComparison.OrdinalIgnoreCase) ) { Indices = new IndexedAttribute[] { new IndexedAttribute() }; } IsNullable = !(IsPK || Orm.IsMarkedNotNull(prop)); MaxStringLength = Orm.MaxStringLength(prop); StoreAsText = prop.PropertyType.GetTypeInfo().CustomAttributes.Any(x => x.AttributeType == typeof(StoreAsTextAttribute)); }