I have my ADO entity generated in MVC 2 and I know that if I want to put custom validation on an object I can do something like this.
[MetadataType(typeof(MyEntity_Validation))]
public partial class MyEntity
{
priv开发者_如何学JAVAate sealed class MyEntity_Validation
{
[Required]
[RegularExpression("[A-Za-z][0-9]{5}")]
public string SomeField{ get; set; }
}
}
But I don't know why that works.
How does that work? Some sort of convention?
Metadata is a convention, yes. See http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.aspx. You can add attributes to fields to enforce validation, display, concurrency, all sorts of common usefulness. Hope this helps.
精彩评论