I'm using Linq to SQL to insert data into a table, but get an SqlException saying that "String or binary data would be truncated". However, the table only consists of two GUIDs, which have an exact size; and a nvarchar(max), and my strings are less than 20 characters.
I tried inserting rows by hand, using SqlCmd, and this worked fine. I also verified using SQL Profiler that nothing gets written tot the trace, indicating the problem is coming from the Linq to SQL framework.
The table definition is:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Results](
[GroupID] [uniqueidentifier] NOT NULL,
[ItemID] [uniqueidentifier] NOT NULL,
[Name] [nvarchar](max) NOT NULL,
PRIMARY KEY (GroupID, ItemID)
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
And the Linq to SQL mapping (from the DBML file) is:
<Table Name="dbo.Results" Member="Results">
<Type Name="Result">
<Column Name="GroupID" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="ItemID" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" />
<Column Name="Name" Type="System.String" DbType="NVarChar(MAX) NOT NULL" CanBeNull="false" />
</Type>
</Table>
And in my C# code, this gives the exception:
db.Results.InsertOnSubmit(new Result
{
GroupID = Guid.NewGuid(),
ItemID = Guid.NewGuid(),
Name = "test"
});
db.SubmitChanges();