I really like the way Entity Frame Code First integrates with MVC3 validation detailed here: http://weblogs.asp.net/scottgu/archive/2010/12/10/class-level-model-validation-with-ef-code-first-and-asp-net-mvc-3.aspx
My 开发者_开发百科question is what other ORM's can be used with MVC3 like this? I'm particularly curious about NHibernate since it seems to be the ORM of choice of many MVC 1 & 2 sites. Are there any add-ons or options to enable attribute based validation that works both client and server side in MVC3?
EDIT: tvanfosson cleared up part of the question put I'd also like to know how validation at the class level works in other ORMs. Will they automatically call Validate on an IValidatableObject?
For instance I can have this class in EF CF:
public class Person
{
[Key]
public int Id { get; set; }
[Email]
public string HomeEmail { get; set;}
}
And then using the DataAnnotationsExtensions NuGet package I can run the following code (outside of MVC even) and get an error.
using (SiteDB db = new SiteDB()) {
db.Persons.Add(new Person() { HomeEmail = "Invalid" });
db.SaveChanges();
}
The DataAnnotations work with the model binder and validation parts of the framework. If you can decoration your model with the attributes, it will work with the baked-in validation. I've used it with both EF and LINQ2SQL as well as view-only models.
You can use :
Linq to sql
Entity Framework
Nhibernate
Fluent Nhibernate
Regards
精彩评论