/// <inheritdoc /> public string GetColumnName(PropertySchema property) { var columnAttribute = property.FindAttribute <ColumnAttribute>(); return(columnAttribute != null ? columnAttribute.Name : property.Name); }
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)); } DbType dbType; if (TypeMapping.TryGetValue(property.EffectiveType, out dbType)) { var allowNull = property.IsNullable || (!property.Type.GetTypeInfo().IsValueType&& property.FindAttribute <RequiredAttribute>() == null); var maxLength = this.GetMaxLength(property); return(new DbTypeEx(dbType, allowNull, maxLength)); } throw new NotSupportedException("Unknown property type: " + property.EffectiveType); }