/// <inheritdoc /> public string GetColumnName(PropertySchema property) { var columnAttribute = property.FindAttribute <ColumnAttribute>(); return(columnAttribute != null ? this.NameEscaper.EscapeColumnName(columnAttribute.Name) : this.GetColumnNameFromType(property)); }
private int?GetMaxLength(PropertySchema property) { if (property.EffectiveType == typeof(char)) { return(1); } return(property.FindAttribute <MaxLengthAttribute>()?.Length); }
private ColumnSchema MakeColumnSchema(int index, PropertySchema property, ColumnUsage columnUsage) { var propertyName = property.Name; return(new ColumnSchema( index, propertyName, this.columnNameConvention.GetColumnName(property), this.nameEscaper.EscapeColumnName(propertyName), propertyName, columnUsage, this.GetDbType(property))); }
private DbTypeEx GetDbType(PropertySchema property) { if (property.EffectiveType.GetTypeInfo().IsEnum) { return(new DbTypeEx(DbType.Int32, property.IsNullable, null)); } if (!this.typeMapping.TryGetValue(property.EffectiveType, out var dbType)) { throw new NotSupportedException("Unknown property type: " + property.EffectiveType); } var allowNull = property.IsNullable || (!property.Type.GetTypeInfo().IsValueType&& property.FindAttribute <RequiredAttribute>() == null); return(new DbTypeEx(dbType, allowNull, this.GetMaxLength(property))); }
private static ColumnUsage GetColumnUsage(bool explicitKeyDefined, PropertySchema property) { var isPrimaryKey = explicitKeyDefined ? property.FindAttribute <KeyAttribute>() != null : string.Equals(property.Name, "Id", StringComparison.OrdinalIgnoreCase); if (!property.PropertyInfo.CanWrite) { return(isPrimaryKey ? ColumnUsage.ComputedPrimaryKey : ColumnUsage.ComputedColumn); } var generatedAttribute = property.FindAttribute <DatabaseGeneratedAttribute>(); return(isPrimaryKey ? GetPrimaryKeyUsage(generatedAttribute) : GetColumnUsage(generatedAttribute)); }
/// <summary> /// Gets the column name from the given property. /// </summary> protected virtual string GetColumnNameFromType(PropertySchema property) { return(this.NameEscaper.EscapeColumnName(property.Name)); }