给定类:
public class Item
{
[Key]
public int ID { get; set; }
[Display]
public string Name { get; set; }
public string Observation { get; set; }
public DateTime? Done { get; set; }
}
我知道我可以通过在另一个项目中创建映射类并从 EntityTypeConfiguration 继承来定义我的 [Key] 属性和其他映射设置。
但是我如何替换 [display] 属性,这样我就不必将对 System.ComponentModel.DataAnnotations 的引用添加到我的公共(public) dll 中?
如果我还不够清楚告诉我
最佳答案
您可以创建自己的属性,然后编写一个继承 AssociatedMetadataProvider
的类,并将属性中的数据读取到 ModelMetadata
实例中。
您的类(class)将与 built-in version 相似或相同.
关于c# - [显示] 属性的替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11083711/