天天看點

ADO.NET Entity Framework中的自增列問題 (Identity)

初次使用 ADO.NET Entity Framework進行資料開發(SQLServer),碰到自增列的問題:

ADO.NET Entity Framework中的自增列問題 (Identity)

如下處理:

在edmx設計界面,修改字段的屬性

ADO.NET Entity Framework中的自增列問題 (Identity)

這裡有三個枚舉值None,Identity,Computed                

 None       預設值,表示該屬性不是伺服器生成的屬性。  

 Identity     插入時生成一個值,更新時該值保持不變。 

 Computed     插入和更新時生成一個值

在完成這步後,XML檔案中CSDL部分的屬性值會被自動添加上annotation:StoreGeneratedPattern="Identity",但SSDL部分還需要手動添加:

ADO.NET Entity Framework中的自增列問題 (Identity)
ADO.NET Entity Framework中的自增列問題 (Identity)

這裡StoreGeneratedPattern無字首.

OK