Home
Register
About
Login
Categories
C#
(13)
VB.NET
(0)
F#
(0)
ASP.NET
(15)
JavaScript
(4)
C++
(0)
C
(0)
Python
(0)
Ruby
(0)
Rails
(0)
J#
(0)
SQL
(0)
VB Script
(0)
HTML
(0)
CSS
(2)
XML
(2)
XSLT
(0)
Unit Testing
(7)
Architecture
(2)
Ajax
(0)
Project Management
(0)
LINQ to SQL
(2)
LINQ
(0)
LINQ to XML
(1)
NHibernate
(0)
Active Record
(0)
Silverlight
(0)
ASP.NET MVC
(0)
Life
(0)
Book Reviews
(0)
WPF
(1)
Visual Studio
(0)
Handling Entity Classes Validation
by azamsharp on 5/6/2008 4:43:47 PM
One of the things that I am really interested in entity classes validation. What is the best practice for validating that the entity class is valid. This means validation properties and stuff. I found that using Custom Attributes is a clean approach and also expandable as you can create more custom attributes.
public class Customer
{
[NotNullOrEmpty]
public string FirstName
{
// whatever
}
}
Customer customer = new Customer();
// assign values to the customer
ValidationEngine.Validate(customer);
if(customer.IsValid) customer.Save();
else // show the broken rules!
Refactor it!
Please log in to refactor the code!
Login