如果模型优先,我们使用[MetadataType(typeof(ConceptMetadataSource))]
附加一个 MetadataSource 文件,其中包含所有数据注释,如 [HiddenInput(DisplayValue = false)]
or [Display(Name = "Title")]
。
例如:
[MetadataType(typeof(ConceptMetadataSource))]
public partial class Concept
...
现在,我正在使用数据库优先的方法,因为有一个现有的数据库。这一次,实体类是由 edmx 模型自动创建的。在每个实体类的开头,下面都有注释行:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
由于一旦我们修改了数据库中的表,代码就会重新生成,因此每次重新生成实体类时,数据注释都会被清除。
谁能告诉我注释这些实体类的最佳方法是什么?谢谢你。