Class-Level Model Validation with EF Code First and ASP.NET MVC 3
page 1 of 7
Published: 10 Dec 2010
Unedited - Community Contributed
Abstract
In this article, Scott examines the technique involved with class-level model validation with EF Code First and ASP.NET MVC 3. After a short introduction, he demonstrates the usage of IValidatableObject and Automatic Validation Enforcement with the help of relevant source code and screenshots.
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 30691/ 99

Introduction

Republished with Permission - Original Article

Earlier this week the data team released the CTP5 build of the new Entity Framework Code-First library.

In my blog post a few days ago I talked about a few of the improvements introduced with the new CTP5 build.  Automatic support for enforcing DataAnnotation validation attributes on models was one of the improvements I discussed.  It provides a pretty easy way to enable property-level validation logic within your model layer.

You can apply validation attributes like [Required], [Range], and [RegularExpression] – all of which are built-into .NET 4 – to your model classes in order to enforce that the model properties are valid before they are persisted to a database.  You can also create your own custom validation attributes (like this cool [CreditCard] validator) and have them be automatically enforced by EF Code First as well.  This provides a really easy way to validate property values on your models.  I showed some code samples of this in action in my previous post.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-10-15 5:21:49 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search