C# 我想使用linq to sql在数据库中插入新行

C# 我想使用linq to sql在数据库中插入新行,c#,asp.net,database,linq-to-sql,insert,C#,Asp.net,Database,Linq To Sql,Insert,我尝试使用linq to sql在数据库的items表中添加新项,如下所示: Items new_item = new Items(); new_item.Title = editproductid.Text; new_item.Path = @"~\images\" + uploadimage.FileName; StaticVa.new_data_context.Items.InsertOnSubmit(new_item

我尝试使用linq to sql在数据库的items表中添加新项,如下所示:

Items new_item = new Items();
            new_item.Title = editproductid.Text;
            new_item.Path = @"~\images\" + uploadimage.FileName;
            StaticVa.new_data_context.Items.InsertOnSubmit(new_item);
            StaticVa.new_data_context.SubmitChanges();
但我有个例外

在以下情况下,无法在表“Items”中插入标识列的显式值 标识\u插入被设置为关闭


我怎样才能打开它?或者还有其他插入方法吗?

您需要确保模型中标识列的“自动生成值”属性设置为True,以便Linq to Sql知道不要尝试插入值本身。

表的主键是什么?