Problem
We recently documented the following changes in v20.1.3:
- XPO may throw OverflowException if String or Byte Array value length (size) is greater than the maximum allowed database column size
- XPO may throw InvalidCastException or SqlExecutionErrorException if parameter types (for update/read queries) do not match database column types
Unfortunately, we failed to anticipate the scope of query parameter inconsistencies within customer apps (EAP/Beta feedback did not uncover this issue). Despite benefits associated with our changes, we do not want to force XPO users to modify their code immediately or revert to previous behavior manually (with feature toggles).
Solution
We softened default parameter validation with regard to SELECT, UPDATE, and INSERT statements in our v20.1.4 release.
We introduced a new DevExpress.Xpo.DB.QueryParameterMode enumeration with the following values:
- Legacy: for v19.2 and older versions.
- SetType (Default): will only validate parameter type without size. Will preserve all performance optimizations. SetType will still catch errors such as Guid parameter comparisons with strings (learn more).
- SetTypeAndSize: will validate type and size. It will be automatically set for MSSqlConnectionProvider and Always Encrypted).
You can set the ConnectionProviderSql.QueryParameterMode property or the ConnectionProviderSql.GlobalQueryParameterMode static property as needed. Example:
using DevExpress.Xpo.DB;
//...
ConnectionProviderSql.GlobalQueryParameterMode = QueryParameterMode.Legacy;
The majority of XPO users will not need to modify this behavior, because new defaults should address most requirements.
Feedback
Please test a new build and let us know how this solution works for you.