【问题标题】:How to keep MetadataType attribute when update class from database?从数据库更新类时如何保留 MetadataType 属性?
【发布时间】:2014-03-16 19:10:34
【问题描述】:

对数据库进行一些更改后,我在 Visual Studio 中单击“从数据库更新类”。当我这样做时,我在每个类上定义的所有数据注释都消失了。所以我开始在类上添加 MetadataType 属性,而不是直接在类上定义 Data Annotation。它变得比以前不那么麻烦了。但现在我有超过 10 个课程,我仍然需要添加 [MetadataType(typeof(Models.MyModelClasses))] 每次我更新数据库时,无论更改多么小,都会再次出现在每个班级上。有没有更好的方法来保留 MetadataType 属性而不是再次键入它?

using System.ComponentModel.DataAnnotations;

[MetadataType(typeof(Models.Employee.EmployeeMetadata))]
public partial class employee
{
    public int ID { get; set; }
    public string PWD { get; set; }
    public string F_NAME { get; set; }
}

【问题讨论】:

标签: entity-framework asp.net-mvc-4 data-annotations metadatatype


【解决方案1】:

this article 似乎可以解决您的问题。

-- 你可能也看那个this SO answer thread

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多