Tuesday 6 December 2011

T4 template solves Linq-to-SQL and String or binary data would be truncated error.

Recently we developed a project using Linq-to-SQL, but we encountered an issue when trying to save data. SQL Server returned an error message “String or binary data would be truncated”. The error message simply means the string we try to insert into database is too long. 
We have a few options to fix the issue, but we created a T4 template that would automatically truncate the string if it is too long. Here is the code.