Last post Mar 30, 2010 09:46 PM by intertek dev
Mar 30, 2010 02:33 PM|intertek dev|LINK
Not much action on the codeplex forum, so I decided to move my thread here.
have a simple scenario that I need some help with.
I have a class file called Address which stores address, city, state, zip, ect, and a class file called Phone which stores the number, phonetype, ect..
Then I have a Business Object called Contact, with a PROPERTY called Address which references a new instance of the address class, and a PROPERTY called Phone which references a new instance of the phone class.
The Address class has its own Validation Attributes decorating the properties, same with the phone class
When I try to Validate the Contact, it does not validate the properties of the address class or the phone class.
How can achieve this functionality?
Below is a sample reproducing the issue.
Public Class Address
<NotNullValidator(MessageTemplate:="Line 1 can not be empty")> _
Public Line1 As String
Public Line2 As String
<NotNullValidator(MessageTemplate:="City can not be empty")> _
Public City As String
Public Class Phone
<NotNullValidator(MessageTemplate:="Number can not be empty")> _
Public Number As String
Public Type As String
Public Class Contact : Inherits BaseDomainObect
Private m_address As Address = New Address
Private m_phone As Phone = New Phone
Public ReadOnly Property Address() As Address
Public ReadOnly Property Phone() As Phone
Private m_Name As String
<NotNullValidator(MessageTemplate:="Name cant be empty")> _
Public Property Name() As String
Set(ByVal value As String)
m_Name = value
Public MustInherit Class BaseDomainObect
Public Function Validate() As ValidationResults
Dim myContact As New Contact
myContact.Name = Nothing
Dim results As ValidationResults
results = Validation.Validate(myContact)
For Each r As ValidationResult In results
MessageBox.Show(r.Key & " " & r.Message)
The only property that gets validated is the Name property.
How can I drill down and validate the properties within the address and phone classes?
Any help would be greatly appreciated.
Mar 30, 2010 09:46 PM|intertek dev|LINK
It seems as though I forgot to add the ObjectValidator Attribute to the Address and Phone properties.
Everything works great now.