public static ColumnDefinition GetColumnDefinition(Type modelType, PropertyInfo propertyInfo, string columnName, string tableName)
        {
            var definition = new ColumnDefinition{ Name = columnName, TableName = tableName, ModificationType = ModificationType.Create };

            //Look for specific Null setting attributed a column
            var nullSettingAttribute = propertyInfo.FirstAttribute<NullSettingAttribute>();
            if (nullSettingAttribute != null)
            {
                definition.IsNullable = nullSettingAttribute.NullSetting == NullSettings.Null;
            }

            //Look for specific DbType attributed a column
            var databaseTypeAttribute = propertyInfo.FirstAttribute<SpecialDbTypeAttribute>();
            if (databaseTypeAttribute != null)
            {
                definition.HasSpecialDbType = true;
                definition.DbType = databaseTypeAttribute.DatabaseType;
            }
            else
            {
                definition.PropertyType = propertyInfo.PropertyType;
            }

            //Look for Primary Key for the current column
            var primaryKeyColumnAttribute = propertyInfo.FirstAttribute<PrimaryKeyColumnAttribute>();
            if (primaryKeyColumnAttribute != null)
            {
                string primaryKeyName = string.IsNullOrEmpty(primaryKeyColumnAttribute.Name)
                                            ? string.Format("PK_{0}", tableName)
                                            : primaryKeyColumnAttribute.Name;

                definition.IsPrimaryKey = true;
                definition.IsIdentity = primaryKeyColumnAttribute.AutoIncrement;
                definition.IsIndexed = primaryKeyColumnAttribute.Clustered;
                definition.PrimaryKeyName = primaryKeyName;
                definition.PrimaryKeyColumns = primaryKeyColumnAttribute.OnColumns ?? string.Empty;
                definition.Seeding = primaryKeyColumnAttribute.IdentitySeed;
            }

            //Look for Size/Length of DbType
            var lengthAttribute = propertyInfo.FirstAttribute<LengthAttribute>();
            if (lengthAttribute != null)
            {
                definition.Size = lengthAttribute.Length;
            }

            //Look for Constraint for the current column
            var constraintAttribute = propertyInfo.FirstAttribute<ConstraintAttribute>();
            if (constraintAttribute != null)
            {
                definition.ConstraintName = constraintAttribute.Name ?? string.Empty;
                definition.DefaultValue = constraintAttribute.Default ?? string.Empty;
            }

            return definition;
        }
        public static ColumnDefinition GetColumnDefinition(Type modelType, PropertyInfo propertyInfo, string columnName, string tableName)
        {
            var definition = new ColumnDefinition{ Name = columnName, TableName = tableName, ModificationType = ModificationType.Create };

            //Look for specific Null setting attributed a column
            var nullSettingAttribute = propertyInfo.FirstAttribute<NullSettingAttribute>();
            if (nullSettingAttribute != null)
            {
                definition.IsNullable = nullSettingAttribute.NullSetting == NullSettings.Null;
            }

            //Look for specific DbType attributed a column
            var databaseTypeAttribute = propertyInfo.FirstAttribute<SpecialDbTypeAttribute>();
            if (databaseTypeAttribute != null)
            {
                definition.HasSpecialDbType = true;
                definition.DbType = databaseTypeAttribute.DatabaseType;
            }
            else
            {
                definition.PropertyType = propertyInfo.PropertyType;
            }

            //Look for Primary Key for the current column
            var primaryKeyColumnAttribute = propertyInfo.FirstAttribute<PrimaryKeyColumnAttribute>();
            if (primaryKeyColumnAttribute != null)
            {
                string primaryKeyName = string.IsNullOrEmpty(primaryKeyColumnAttribute.Name)
                                            ? string.Format("PK_{0}", tableName)
                                            : primaryKeyColumnAttribute.Name;

                definition.IsPrimaryKey = true;
                definition.IsIdentity = primaryKeyColumnAttribute.AutoIncrement;
                definition.IsIndexed = primaryKeyColumnAttribute.Clustered;
                definition.PrimaryKeyName = primaryKeyName;
                definition.PrimaryKeyColumns = primaryKeyColumnAttribute.OnColumns ?? string.Empty;
                definition.Seeding = primaryKeyColumnAttribute.IdentitySeed;
            }

            //Look for Size/Length of DbType
            var lengthAttribute = propertyInfo.FirstAttribute<LengthAttribute>();
            if (lengthAttribute != null)
            {
                definition.Size = lengthAttribute.Length;
            }

            //Look for Constraint for the current column
            var constraintAttribute = propertyInfo.FirstAttribute<ConstraintAttribute>();
            if (constraintAttribute != null)
            {
                //Special case for MySQL as it can't have multiple default DateTime values, which 
                //is what the umbracoServer table definition is trying to create
                if (SqlSyntaxContext.SqlSyntaxProvider is MySqlSyntaxProvider && definition.TableName == "umbracoServer" &&
                        definition.TableName.ToLowerInvariant() == "lastNotifiedDate".ToLowerInvariant())
                    return definition;

                definition.ConstraintName = constraintAttribute.Name ?? string.Empty;
                definition.DefaultValue = constraintAttribute.Default ?? string.Empty;
            }

            return definition;
        }
 public AlterColumnExpression()
 {
     Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
 }
 public AlterColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders) : base(current, databaseProviders)
 {
     Column = new ColumnDefinition() { ModificationType = ModificationType.Alter };
 }
 public CreateColumnExpression()
 {
     Column = new ColumnDefinition { ModificationType = ModificationType.Create };
 }
 public CreateColumnExpression(DatabaseProviders current, DatabaseProviders[] databaseProviders)
     : base(current, databaseProviders)
 {
     Column = new ColumnDefinition { ModificationType = ModificationType.Create };
 }
        public static ColumnDefinition GetColumnDefinition(ISqlSyntaxProvider syntaxProvider, Type modelType, PropertyInfo propertyInfo, string columnName, string tableName)
        {
            var definition = new ColumnDefinition {
                Name = columnName, TableName = tableName, ModificationType = ModificationType.Create
            };

            //Look for specific Null setting attributed a column
            var nullSettingAttribute = propertyInfo.FirstAttribute <NullSettingAttribute>();

            if (nullSettingAttribute != null)
            {
                definition.IsNullable = nullSettingAttribute.NullSetting == NullSettings.Null;
            }

            //Look for specific DbType attributed a column
            var databaseTypeAttribute = propertyInfo.FirstAttribute <SpecialDbTypeAttribute>();

            if (databaseTypeAttribute != null)
            {
                definition.HasSpecialDbType = true;
                definition.DbType           = databaseTypeAttribute.DatabaseType;
            }
            else
            {
                definition.PropertyType = propertyInfo.PropertyType;
            }

            //Look for Primary Key for the current column
            var primaryKeyColumnAttribute = propertyInfo.FirstAttribute <PrimaryKeyColumnAttribute>();

            if (primaryKeyColumnAttribute != null)
            {
                string primaryKeyName = string.IsNullOrEmpty(primaryKeyColumnAttribute.Name)
                                            ? string.Format("PK_{0}", tableName)
                                            : primaryKeyColumnAttribute.Name;

                definition.IsPrimaryKey      = true;
                definition.IsIdentity        = primaryKeyColumnAttribute.AutoIncrement;
                definition.IsIndexed         = primaryKeyColumnAttribute.Clustered;
                definition.PrimaryKeyName    = primaryKeyName;
                definition.PrimaryKeyColumns = primaryKeyColumnAttribute.OnColumns ?? string.Empty;
                definition.Seeding           = primaryKeyColumnAttribute.IdentitySeed;
            }

            //Look for Size/Length of DbType
            var lengthAttribute = propertyInfo.FirstAttribute <LengthAttribute>();

            if (lengthAttribute != null)
            {
                definition.Size = lengthAttribute.Length;
            }

            //Look for Constraint for the current column
            var constraintAttribute = propertyInfo.FirstAttribute <ConstraintAttribute>();

            if (constraintAttribute != null)
            {
                //Special case for MySQL as it can't have multiple default DateTime values, which
                //is what the umbracoServer table definition is trying to create
                if (syntaxProvider is MySqlSyntaxProvider && definition.TableName == "umbracoServer" &&
                    definition.TableName.ToLowerInvariant() == "lastNotifiedDate".ToLowerInvariant())
                {
                    return(definition);
                }

                definition.ConstraintName = constraintAttribute.Name ?? string.Empty;
                definition.DefaultValue   = constraintAttribute.Default ?? string.Empty;
            }

            return(definition);
        }