[英]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.