简体   繁体   English

从数据库更新类时如何保留MetadataType属性?

[英]How to keep MetadataType attribute when update class from database?

After I made some changes on my database, I click "Update class from Database" in Visual Studio. 在数据库上进行了一些更改后,在Visual Studio中单击“从数据库更新类”。 When i do that all the Data Annotation i defined on each class disappeared. 当我这样做时,我在每个类上定义的所有数据注释都消失了。 So I started to adding MetadataType attribute on classes instead of defining Data Annotation directly on the classes. 因此,我开始在类上添加MetadataType属性,而不是直接在类上定义数据注释。 It becomes less cumbersome than before. 与以前相比,它不再那么麻烦。 But now i have more than 10 classes and i still need to add [MetadataType(typeof(Models.MyModelClasses))] on each class again every time i update database no matter how small the changes are. 但是现在我有10个以上的类,无论更改有多小,每次更新数据库时,我仍然需要在每个类上再次添加[MetadataType(typeof(Models.MyModelClasses))] Are there any better ways to keep MetadataType attribute instead of typing it again? 有没有更好的方法来保留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; }
}

this article appears to address your issue. 本文似乎是在解决您的问题。

-- You might also look that this SO answer thread . -您可能还会看到该SO答复线程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当edmx更改时,MetadataType属性将被删除 - MetadataType attribute removs when edmx change 更新数据库类中的一个属性 - Update One attribute in database class 在执行“从数据库更新 Model”时,如何防止我的 model 文件被刷新? - How can I keep my model files from being refreshed when doing an "Update Model from Database"? MetadataType属性不适用于MVC3中的详细信息视图 - MetadataType attribute is not working for details view in MVC3 为什么MetadataType不在数据库第一种方法中进行验证? - Why MetadataType doesn't do my validation in database first approach? ef从数据库更新模型时,如何在不重新创建新DomainService文件的情况下更新DomainService? - ef when update model from database, how to update DomainService without recreating a new DomainService file? 使用带有后处理属性拦截的EF元数据类型模型类不起作用 - using EF metadatatype model class with postsharp property interception not working 从模型更新数据库(模型更改时)? - Update Database from Model (when model changed)? 如何以编程方式“从数据库更新模型”? - How to “Update Model From Database” programatically? 如何从现有数据库更新 Symfony 实体? - How to update Symfony Entities from an existing database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM