C# – SubSonic: MaxLength of TableColumn (exceeding)

cMySQLsubsonicsubsonic2.2

So, we're using SubSonic as our DAL/ORM for one of our projects. Everything has been running smoothly (the database already existed, so we used SubSonic on top of it), however, on occasion we'll run into an exception that says something like the integer is exceeding the max length. In this example, our MySql field is an int(4) signed. Which, according to MySql documentation will allow a range of the following:

-2147483647 to 2147483647.

Now, my question, how is MaxLength dictated in SubSonic? Is it the number of digits? Because that means it would only allow -9999 to 9999, correct? That seems like a rather huge discrepancy, and I'm hoping that isn't the case, or else we're going to have a ton of other problems.

Thanks,
-Steve

Best Answer

Using Reflector, and drilling down to ActiveRecord's Save function (which calls ValidateColumnSettings):

 if ((!flag && (column.MaxLength > 0)) && ((column.DataType != DbType.Boolean) && (currentValue.ToString().Length > column.MaxLength)))
        {
            Utility.WriteTrace(string.Format("Max Length Exceeded {0} (can't exceed {1}); current value is set to {2}", column.ColumnName, column.MaxLength, currentValue.ToString().Length));
            this.errorList.Add(string.Format(this.LengthExceptionMessage, str, column.MaxLength));
        }

flag is set to true if the variable is null. So, yes, it's going off of the number of digits (see: ToString().Length). This doesn't seem to make any sense, since MySql doesn't use the length property of the data type to determine the number of digits for integer based values.

This is SubSonic 2.2.

Related Topic