天天看点

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