0
我試圖使用LINQ插入一行到表不工作,並表的ID列具有識別規格:標識規範Linq中
CREATE TABLE [dbo].[Event](
[ID] [int] IDENTITY(36,1) NOT NULL,
[Description] [nvarchar](100) NOT NULL,
[OccurredDateTime] [datetime] NULL,
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
我有身份的規範佔在我的Visual Studio項目的DBML文件中:
[Table(Name="dbo.Event")]
public partial class Event : INotifyPropertyChanging, INotifyPropertyChanged
{
/* ... */
[Column(Storage="_ID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int ID
{
/* ... */
}
/* ... */
}
怎麼回事?當我嘗試插入這樣的:
Data.Event myEvent = new Data.Event();
myEvent.Description = summaryText;
db.Events.InsertOnSubmit(myEvent);
db.SubmitChanges();
以下異常被拋出:
SQLEXCEPTION:無法插入值 NULL插入列 'ID',表 'redacted.dbo.Event' ;列不會 允許空值。 INSERT失敗。 聲明已被終止
我想我在連接字符串中指定了錯誤的數據庫。仍然試圖讓我的測試設置來驗證... – 2010-11-09 19:45:03