Exemplo n.º 1
0
        protected virtual string GetStringLengthValidator(DiffTable table, DiffColumn col, string relatedEntity)
        {
            if (GetValueType(col) != typeof(string))
            {
                return(null);
            }

            var parts = new List <string>();

            parts.Add("AllowNulls = " + col.Nullable.ToString().ToLower());

            var min = GetMinStringLength(col);

            if (min != null)
            {
                parts.Add("Min = " + min);
            }

            if (col.Length != -1)
            {
                parts.Add("Max = " + col.Length / DiffColumn.BytesPerChar(col.SqlDbType));
            }

            return("StringLengthValidator(" + parts.ToString(", ") + ")");
        }
        protected virtual List<string> GetSqlDbTypeParts(DiffColumn col, Type type)
        {
            List<string> parts = new List<string>();
            var pair = CurrentSchema.Settings.GetSqlDbTypePair(type);
            if (pair.SqlDbType != col.SqlDbType)
                parts.Add("SqlDbType = SqlDbType." + col.SqlDbType);

            var defaultSize = CurrentSchema.Settings.GetSqlSize(null, pair.SqlDbType);
            if (defaultSize != null)
            {
                if (!(defaultSize == col.Precission || defaultSize == col.Length / DiffColumn.BytesPerChar(col.SqlDbType) || defaultSize == int.MaxValue && col.Length == -1))
                    parts.Add("Size = " + (col.Length == -1 ? "int.MaxValue" :
                                        col.Length != 0 ? (col.Length / DiffColumn.BytesPerChar(col.SqlDbType)).ToString() :
                                        col.Precission != 0 ? col.Precission.ToString() : "0"));
            }

            var defaultScale = CurrentSchema.Settings.GetSqlScale(null, col.SqlDbType);
            if (defaultScale != null)
            {
                if (!(col.Scale == defaultScale))
                    parts.Add("Scale = " + col.Scale);
            }

            if (col.Default != null)
                parts.Add("Default = \"" + CleanDefault(col.Default) + "\"");

            return parts;
        }