gpt4 book ai didi

c# - ASP.NET Core Entity Framework 代码到数据库脚手架无法识别 Id 属性或 [Key] 注释

转载 作者:行者123 更新时间:2023-12-01 19:47:59 25 4
gpt4 key购买 nike

我正在尝试为我的 Ticket 类搭建一个 razor 页面集,当 Entity Framework 尝试创建数据库时出现错误:

This shows the error next to my "Ticket" definition which includes a Key annotation above an "Id" property

我的理解是,如果您有一个属性“Id”,它会使用它,如果您设置 [Key] 注释,它会专门告诉 Entity Framework 使用该属性。我拥有这两样东西,那么有什么好处呢?

最佳答案

公开您的属性。

public int Id { get; set; }

关于c# - ASP.NET Core Entity Framework 代码到数据库脚手架无法识别 Id 属性或 [Key] 注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62223042/

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