加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 自动生成ID GUID数据类型实体框架

发布时间:2020-12-15 04:37:30 所属栏目:百科 来源:网络整理
导读:我看过这篇文章并尝试这样做 Autogenerate primary key (Guid) Entity Framework CTP5 [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid CompanyID { set; get; } 但是我仍然得到错误 Identity column 'CompanyID' must be of data t

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

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密钥创建一个新迁移:

> Update-Database -TargetMigration:0
>删除所有迁移
> Add-Migration InitialCreate
>更新 – 数据库

我同意这不是最好的解决方案,但我可以接受,因为我几个小时前就开始了项目.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读