コード例 #1
0
        /// <inheritdoc />
        public string GetColumnName(PropertySchema property)
        {
            var columnAttribute = property.FindAttribute <ColumnAttribute>();

            return(columnAttribute != null
                ? columnAttribute.Name
                : property.Name);
        }
コード例 #2
0
        private int?GetMaxLength(PropertySchema property)
        {
            if (property.EffectiveType == typeof(char))
            {
                return(1);
            }

            return(property.FindAttribute <MaxLengthAttribute>()?.Length);
        }
コード例 #3
0
        private ColumnSchema MakeColumnSchema(IDialect dialect, PropertySchema property, ColumnUsage columnUsage)
        {
            var propertyName = property.Name;

            return(new ColumnSchema(
                       dialect.MakeColumnName(this.columnNameFactory.GetColumnName(property)),
                       dialect.MakeColumnName(propertyName),
                       propertyName,
                       columnUsage,
                       this.GetDbType(property)));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }