问题描述
我使用MVC 4,用数据库第一。
I'm using mvc 4, with database first.
每次我刷新 model.edmx
文件,我添加了显示名称属性被删除。我怎样才能保持地方显示名称刷新之间的属性?
Everytime I refresh the model.edmx
file, the display name attribute I added is removed. How can I the keep display name attribute between refreshes?
推荐答案
您会希望使用 System.ComponentModel.DataAnnotations
。下面是在EF一个用户表中简单的例子来告诉你如何:
You are going to want to use System.ComponentModel.DataAnnotations
. Here is a simplistic Example for a 'User' table in EF to show you how:
namespace YourNamespace.BlaBlaBla
{
[MetadataType(typeof(UserHelper))]
public partial class User { }
public class UserHelper
{
[Display(Name = "Your New Title For Name")]
public string Name { get; set; }
}
}
您还可以在你的类审定及。可以肯定的是名为完全相同的一个分部类 - 也不要忘记它的必须的是完全相同的命名空间的.edmx你。
You can also include validation in your class as well. Be sure it is a partial class named the exact same - also do not forget that it must be in the exact same namespace as your .edmx.
这篇关于MVC DB首次定位显示名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!