Is there any way to use an Entity as a model, and be able to decorate its fields in order to get validation? I am using the Entity as a model for convenience, but then I need to do all the validation manually...
+1
A:
Found it!
Say Course is the entity.
You then implement these two:
namespace MyNamespace.Models {
[MetadataType(typeof(CourseMetadata))]
public partial class Course {
}
public class CourseMetadata {
[DisplayName("Course location")]
[Required]
public string place {get; set;}
}
}
The first declares that the metadata for Course are taken from CourseMetadata, the second one contains the same fields as the Course, with the only purpose to inject metadata onto them. Cool :D
Palantir
2010-04-16 13:34:35