SQL Server Compact不支持服务器生成的密钥和服务器生成的值 [英] Server-generated keys and server-generated values are not supported by SQL Server Compact
问题描述
我刚刚开始玩实体框架,所以我决定将它连接到我现有的SQL Server CE数据库。我有一个带有IDENTITY(1,1)主键的表,但是当我尝试添加一个实体时,我有上述错误。
I just started to play with the entity framework, so I decided to connect it to my existing SQL Server CE database. I have a table with an IDENTITY(1, 1) primary key but when I tried to add an entity, I've got the above-mentioned error.
从< a href =http://technet.microsoft.com/en-us/library/cc835494.aspx =noreferrer> MS Technet artice 我了解到,
当与实体框架一起使用时,SQL Server Compact不支持具有服务器生成的键或值的实体。
使用实体框架时,实体的键可能会被标记为服务器生成。这使得数据库能够为插入或实体创建的密钥生成一个值。另外,实体的零个或多个属性可能被标记为服务器生成的值。有关更多信息,请参阅实体框架文档中的存储生成模式主题。
虽然实体框架允许您使用服务器生成的键或值来定义实体类型,但是与实体框架一起使用时,SQL Server Compact不支持具有服务器生成的键或值的实体。对具有服务器生成值的实体的数据操纵操作会抛出不支持异常。
SQL Server Compact does not support entities with server-generated keys or values when it is used with the Entity Framework. When using the Entity Framework, an entity’s keys may be marked as server generated. This enables the database to generate a value for the key on insertion or entity creation. Additionally, zero or more properties of an entity may be marked as server-generated values. For more information, see the Store Generated Pattern topic in the Entity Framework documentation. SQL Server Compact does not support entities with server-generated keys or values when it is used with the Entity Framework, although the Entity Framework allows you to define entity types with server-generated keys or values. Data manipulation operation on an entity that has server-generated values throws a "Not supported" exception.
所以现在我有几个问题:
So now I have a few questions:
- 如果不支持将密钥标记为服务器生成,并将抛出异常?
- 当我尝试向我的实体的属性添加StoreGeneratedPattern =Identity时,Studio抱怨说它是不允许的。我在做什么错?
- 这个限制的最佳解决方法是什么(包括切换到另一个数据库)?我的限制是零安装和使用实体框架。
推荐答案
当我遇到这个限制时,我将类型更改为uniqueidentifier
When I hit this limitation, I changed the type to uniqueidentifier
这篇关于SQL Server Compact不支持服务器生成的密钥和服务器生成的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!