1.已有类为partial,部分类(public partial class User)
2.设计类为partial,添加嵌套类(private class MetaUser),嵌套类设计已有类字段
3.设计类添加[MetaDataType(typeof(MetaUser))]
public partial class UserInfo { public string Name { get; set; } } [MetadataType(typeof(MetaUserInfo))] public partial class UserInfo { private class MetaUserInfo { [Required(ErrorMessage = "Name can not empty!")] public string Name { get; set; } } }