gpt4 book ai didi

c# - 自动生成 ID GUID 数据类型 Entity Framework

转载 作者:太空狗 更新时间:2023-10-29 23:30:19 28 4
gpt4 key购买 nike

我看过这篇文章并尝试这样做

Autogenerate primary key (Guid) Entity Framework CTP5

 [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid CompanyID { set; get; }

但是还是报错

Identity column 'CompanyID' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.

这是我在包管理器控制台上运行 Update-Database 命令的时候。

最佳答案

有同样的问题,唯一帮助我的是将数据库降到初始空状态,删除所有迁移并使用正确的 GUID 键创建一个新的迁移:

  1. 更新数据库-TargetMigration:0
  2. 删除所有迁移
  3. 添加迁移 InitialCreate
  4. 更新数据库

我同意这不是最佳解决方案,但对我来说是可以接受的,因为我在几个小时前就开始了项目。

关于c# - 自动生成 ID GUID 数据类型 Entity Framework ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31702557/

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