BO Mapper not generate same types that SQL Server have on FieldNativeDbTypes


Author
Message
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Hello, I try to automate validations on BO's to avoid to send to sql engine invalid fields with numeric types (out of valid range)

I see that the BOM replaces the type of data on FieldNativeDbTypes (example: money as decimal).

Exist some method or anything that I can use to avoid to get schema from SQL? 

If not exist anything that I missed out, I have to make on a base BO a property called OriginalType and put here the original values from sql to parse it correct.

On the example that I post below.... because I have money field serialized in BO as decimal, If I put 99999999999999999999 (nine x 20 times) as a decimal value it validate as OK, but when the BO try to save to SQL the column is money and SQL throws a error.

Thanks in advance.

Code that I try to use without sucess:

decimal parsedValue = 0;
if (!decimal.TryParse(value.ToString(), out parsedValue)) {
  AddBrokenRule(field, "el valor del campo es incorrecto (no puede procesarse)");
  return;
}

switch (FieldNativeDbTypes[field]) {
  case (int)SqlDbType.BigInt:
    if (parsedValue < Int64.MinValue || parsedValue > Int64.MaxValue)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: -9223372036854775808 a 9223372036854775807)");
      break;

  case (int)SqlDbType.Int:
    if (parsedValue < Int32.MinValue || parsedValue > Int32.MaxValue)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: -2147483648 a 2147483647)");
      break;

  case (int)SqlDbType.Money: // !!THIS IS NOT USED BECAUSE BO TRANSLATEs MONEY TO DECIMAL ON PARTIAL (designer) !!!
    if (parsedValue < -922337203685 || parsedValue > 922337203685)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: -922337203685 a 922337203685)");
      break;

  case (int)SqlDbType.SmallInt:
    if (parsedValue < Int16.MinValue || parsedValue > Int16.MaxValue)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: -922337203685 a 922337203685)");
      break;

  case (int)SqlDbType.SmallMoney:
    if (parsedValue <  -214748 || parsedValue > 214748)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: -922337203685 a 922337203685)");
      break;

  case (int)SqlDbType.TinyInt:
    if (parsedValue < byte.MinValue || parsedValue > byte.MaxValue)
      AddBrokenRule(field, "el valor del campo es incorrecto (valido: 0 a 255)");
      break;

  case (int)SqlDbType.Decimal: 
    if (parsedValue < decimal.MinValue || parsedValue > decimal.MaxValue)
      AddBrokenRule(field, "el valor del campo es incorrecto");
      break;

//  case (int)SqlDbType.Float: // http://msdn.microsoft.com/es-es/library/ms173773.aspx
//    break;
//  case (int)SqlDbType.Real: // ES MUY GRANDE...
//    break;
// switch 
Edited 12 Years Ago by Fabian R Silva, -
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search