private static string GenerateColumnDefaultConstraint(ColumnModel column, string command)
        {
            // Obtain annotation info
            var deserialize = true;
            AnnotationValues values;

            column.Annotations.TryGetValue(DefaultConstraintAnnotationConvention.AnnotationName, out values);
            if (values == null)
            {
                column.Annotations.TryGetValue(DefaultValueAnnotationConvention.AnnotationName, out values);
                if (values == null)
                {
                    return(command);
                }
                deserialize = false;
            }

            // Do SQL generation for column using annotation value as appropriate.
            var serialized = values.NewValue as string;

            // Exit if no value is defined.
            if (serialized == null)
            {
                return(command);
            }

            // Remove any other default constraint.
            var indexOfDefault = command.IndexOf(" DEFAULT ", StringComparison.InvariantCulture);

            if (indexOfDefault > 0)
            {
                command = command.Remove(indexOfDefault);
            }

            // Bind the constraint.
            string name;
            string value;

            if (deserialize)
            {
                var config = DefaultConstraintConfiguration.Deserialize(serialized);
                name  = config.Name;
                value = config.Value;
            }
            else
            {
                name  = null;
                value = serialized;
            }
            if (!string.IsNullOrWhiteSpace(name))
            {
                command += " CONSTRAINT [" + name + "]";
            }
            return(command + " DEFAULT " + value);
        }
        private static string AnnotationFactory(PropertyInfo propertyInfo, IList <DefaultConstraintAttribute> defaultValueAttributes)
        {
            var attribute = defaultValueAttributes.First();

            var config = new DefaultConstraintConfiguration
            {
                Name  = attribute.Name,
                Value = attribute.Value
            };

            return(config.Serialize());
        }
        private bool GenerateColumnDefaultConstraint(AnnotationValues annotationValues, string tableName, string columnName)
        {
            if (annotationValues == null)
            {
                return(false);
            }
            var oldValue = annotationValues.OldValue as string;
            var newValue = annotationValues.NewValue as string;
            var modified = false;

            // Drop default value.
            if (oldValue != null)
            {
                var config = DefaultConstraintConfiguration.Deserialize(oldValue);
                using (var writer = Writer())
                {
                    DropColumnDefaultConstraint(writer, tableName, columnName, config.Name);
                    Statement(writer);
                }
                modified = true;
            }

            // Create default value.
            if (newValue != null)
            {
                var config = DefaultConstraintConfiguration.Deserialize(newValue);
                using (var writer = Writer())
                {
                    CreateColumnDefaultConstraint(writer, tableName, columnName, config.Name, config.Value);
                    Statement(writer);
                }
                modified = true;
            }

            return(modified);
        }