/// <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 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)); }
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))); }