EF Exception: String or binary data would be truncated. The statement has been terminated.? EF Exception: String or binary data would be truncated. The statement has been terminated.? sql-server sql-server

EF Exception: String or binary data would be truncated. The statement has been terminated.?


catch (DbEntityValidationException ex){    foreach (var item in ex.EntityValidationErrors)    {        //... inspect here     }}

You can find the information you need inside foreach loop.

Hope that helps.


You can't at that level. SQL Server is rejecting the entire query.

I would add some pre-checks to the data against your database constraints for string size, date formats, etc.

Alternatively you could TRIM each string field in the raw data to the corresponding field size before trying to insert.


You can check data before saving, using EF metadata, and raise appropriate error.