AlterColumn - "String or binary data would be truncated"

127 views
Skip to first unread message

Scotty Wakefield

unread,
Oct 27, 2014, 7:38:43 AM10/27/14
to fluentmigrato...@googlegroups.com
I am altering a column from nvarchar(150) to nvarchar(100) but want to be able to truncate values if they are over 100 length.

Is there any way other than using Execute.Sql() to update rows with using existing column values? I am trying to avoid coupling to a specific DB.

I have looked at 

Update.Table("tblName").Set(new {colName = "existing val of colName??"});

but I can't get at the existing value. Is there something like:

Update.Table("tblName")
.Set(tbl => new { colName = tbl.Column("colName").AsString(150).SubString(0, 100) });

What other strategies have people used to avoid the truncation error, "String or binary data would be truncated", when using AlterColumn?
Reply all
Reply to author
Forward
0 new messages