gpt4 book ai didi

entity-framework - SQL Server Compact 不支持服务器生成的键和服务器生成的值

转载 作者:行者123 更新时间:2023-12-03 07:58:04 25 4
gpt4 key购买 nike

我刚开始使用 Entity Framework ,所以我决定将它连接到我现有的 SQL Server CE 数据库。我有一个带有 IDENTITY(1, 1) 主键的表,但是当我尝试添加实体时,出现上述错误。

来自 MS Technet artice我了解到

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.



所以现在我有几个问题:
  • 如果不支持 key 并且会引发异常,为什么要将 key 标记为服务器生成?从引用的段落中很难理解。
  • 当我尝试将 StoreGeneratedPattern="Identity"添加到我的实体属性时,Studio 提示说这是不允许的。我做错了什么?
  • 这种限制的最佳解决方法是什么(包括切换到另一个数据库)?我的限制是零安装和使用 Entity Framework 。
  • 最佳答案

    当我达到这个限制时,我将类型更改为 uniqueidentifier

    关于entity-framework - SQL Server Compact 不支持服务器生成的键和服务器生成的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/648449/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com