gpt4 book ai didi

c# - MVC 4 中的部分实体类未显示数据注释

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

我看过很多关于如何通过部分类向 Entity Framework 生成的类添加元数据注释的解释,数据库优先

有人能告诉我为什么这些新显示值没有显示在我的 View 中吗?这两个都是与我的 Entity Framework 生成的类相同的命名空间的一部分。

[MetadataType(typeof(xRef_CodesMetadata))]
public partial class xRef_Codes
{
}

public class xRef_CodesMetadata
{
public int CodeID { get; set; }
public int CTB_ID { get; set; }

[Required(ErrorMessage = "Please type a name")]
[Display(Name = "Code Name")]
[Column(TypeName = "Code Name")]
public string CodeName { get; set; }

[Required(ErrorMessage = "Please type a Description")]
[Display(Name = "Description")]
[Column(TypeName = "Description")]
public string Description { get; set; }
}

View 片段:

<th>
@Html.DisplayNameFor(model => model.OfCodeID)
</th>
<th>
@Html.DisplayNameFor(model => model.CodeName)
</th>
<th>
@Html.DisplayNameFor(model => model.Description)
</th>

最佳答案

这已经解决了!我已经看了 30 个或 40 个关于为什么这个 Entity Framework “数据库优先”部分类不起作用的教程。然后我发现这篇帖子给出了以下建议:

Sorry this is so late, but I just solved a similar scenario myself. I believe the line

[MetadataType(typeof(CompanyMD))]

belongs in the partial class generated by the EF, even though it will be erased if and when you change the model. So your EF-generated file should look like this:

要查看帖子的其余部分,请访问此链接... MVC 4 EF5 Database First set Default Values in Partial Class

关于c# - MVC 4 中的部分实体类未显示数据注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14412468/

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