A common problem in LINQ2SQL is while the .NET String allows assigning any length to its variable, your database may have a specific max length constraint (like VARCHAR(5)). This will lead to the SQL error message "String or binary data would be truncated.", which is extremely unhelpful since it doesn't tell you which fields is the culprit.
Obviously, validating the input for the maximum string length will be the correct way. The main problem I faced is creating the necessary validation for every LINQ object in my project, and updating the validation if the maximum length of the field is updated.
Ideally, I need to work out a way to dynamically determine the max length of a generated field, so I do not risk forgetting to update the validation later.
The best possible implementation I can find so far is "Integrating xVal Validation with Linq-to-Sql", which is already far superior to anything I can think. The only uncertain point is the dynamically determine the max length.
Has anyone seen or implemented anything similar?