There are many examples of how to "create your own model." Check their DataAnnotations. Scott Guthrie explains how to test his model using ORM . What I do not find is when your model really comes from an external DLL. How do you check it?
Example:
public class Person
{
public string Name{get;set;}
public int Age {get;set;}
}
The solution I'm thinking of: Inherit an external class, and then apply [MetadataType] to the inherited class.
[Metadata(typeof(Person2_Validation))]
public class Person2:Person{}
public class Person2_Validation
{
[Required,Stringlength(50,ErrorMessage="Name required"]
public string Name{get;set;}
[RegularExpression("([0-9]+)")]
public int Age
}
Is there a better way?
source
share