Asp.net mvc 实体框架生成类的数据注释
我正在使用MVC 5和实体框架(6.0.2),我的一个类生成为:Asp.net mvc 实体框架生成类的数据注释,asp.net-mvc,entity-framework,Asp.net Mvc,Entity Framework,我正在使用MVC 5和实体框架(6.0.2),我的一个类生成为: public partial class Proc_Result { public int Id { get; set; } public string RegistrationNumber { get; set; } public string Name { get; set; } public Nullable<System.DateTime> DateOfEntry { get;
public partial class Proc_Result
{
public int Id { get; set; }
public string RegistrationNumber { get; set; }
public string Name { get; set; }
public Nullable<System.DateTime> DateOfEntry { get; set; }
public string Drawer { get; set; }
}
公共部分类处理结果
{
公共int Id{get;set;}
公共字符串注册号{get;set;}
公共字符串名称{get;set;}
公共可为空的开始日期{get;set;}
公共字符串抽屉{get;set;}
}
我想让DateOfEntry具有以下数据注释:
[DisplayFormat(DataFormatString=“{0:dd/MM/yyyy}”,ApplyFormatInEditMode=true)]
除了能够将[DisplayName(…)]添加到其他字段之外,这是否可行?我知道我可以手动更改生成的cs文件,但无论何时从db更新,我都会丢失这些更改。否则,我可以建立自己的模型并绘制地图,但我想看看是否有其他方法
我曾考虑创建另一个名为Proc_Result的分部类,但如果只包含相同的开始日期,它会覆盖另一个吗?我在这里找到了解决方案:
基本上我必须这样做:
[MetadataType(typeof(Proc_ResultMetaData))]
public partial class Proc_Result
{
// Note this class has nothing in it. It's just here to add the class-level attribute.
}
public partial class Proc_ResultMetaData
{
public int Id { get; set; }
[DisplayName("Registeration Number")]
public string RegistrationNumber { get; set; }
public string Name { get; set; }
[DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> DateOfEntry { get; set; }
public string Drawer { get; set; }
}
[元数据类型(typeof(Proc_ResultMetaData))]
公共部分类过程结果
{
//注意,这个类中没有任何内容。它只是在这里添加class-level属性。
}
公共部分类Proc_ResultMetaData
{
公共int Id{get;set;}
[显示名称(“注册号”)]
公共字符串注册号{get;set;}
公共字符串名称{get;set;}
[DisplayFormat(DataFormatString=“{0:MM/dd/yyyy}”,ApplyFormatInEditMode=true)]
公共可为空的开始日期{get;set;}
公共字符串抽屉{get;set;}
}
这让它起作用了