gpt4 book ai didi

mysql - Entity Framework 4.2 模型生成异常

转载 作者:行者123 更新时间:2023-11-30 23:34:07 24 4
gpt4 key购买 nike

我试图保留两个类:ForumPost 和 ForumReply。它们的所有属性要么具有相应的表格列,要么标有 [NotMapped]。两个表都标记了主键列。事实上,我已经完全按照 Pro ASP.NET MVC 3 Framework (http://www.amazon.com/Pro-ASP-NET-MVC-3-Framework/dp/1430234040) 一书中的指示做了他们的 Ch7 教程,但在尝试将概念转化为我自己的项目时中断了。错误如下:

在模型生成过程中检测到一个或多个验证错误:

System.Data.Edm.EdmEntityType: : EntityType 'ForumPost' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntityType: : EntityType 'ForumReply' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �ForumPosts� is based on type �ForumPost� that has no keys defined.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �ForumReplies� is based on type �ForumReply� that has no keys defined.

最佳答案

Keys是int还是string?
请记住,长度超过 255 的字符串不能用作键。
如果您的 key 实际上是一个字符串,请使用 [Key, Required, MaxLength(255)] (或更少)。

关于mysql - Entity Framework 4.2 模型生成异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9023513/

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