我只是尝试为工具生成的LLBLGenPro ( partial )类声明分部类,以便可以使用DataAnnotation进行验证。然而,事情似乎在这里不起作用。
下面是我的代码:
namespace MyApp.DataLayer.EntityClasses
{
[Serializable]
public partial class LoginEntity : CommonEntityBase, ISerializable
{
.....
}
}而对于DataAnnotations ..。
namespace MyApp.DataLayer.EntityClasses
{
[MetadataType(typeof(LoginEntityValidation))]
public partial class LoginEntity
{
}
public class LoginEntityValidation
{
[Required(ErrorMessage = "Required !")]
public string Username { get; set; }
}
}//这会出现编译时错误"MyApp.DataLayer.EntityClasses.LoginEntity‘不包含接受1个参数的构造函数“等等。
有没有办法让它工作起来?
提前感谢!
发布于 2011-04-12 20:07:12
不应在视图中使用实体类。您应该使用ViewModel类并将验证放在那里。对于实体->视图模型转换,您可以使用AutoMapper
https://stackoverflow.com/questions/5634632
复制相似问题