Server Side Validation

Apr 3, 2012 at 6:04 AM
Edited Apr 3, 2012 at 6:04 AM

Hi,

I really love the T4 you have created here. Very powerful stuff and thank you for your contributions. I was wondering if you could perhaps give an example of doing a server side validation check, such as checking the server for a duplicate record in the validation partial classes at the entity level.

Ive been stuck trying to figure our how this validation should be done using self tracking entities. Another question I had was why is the propertychanged event in the T4 a private member? If I wanted to subscribe to the property changed event of an entity would I need to modify the T4 template first? Any help would be greatly appreciated.

 

Thank you very much for your time!

Coordinator
Apr 3, 2012 at 2:12 PM

For checking whether there is a duplicate record in the database or not, I think we should add that type of validation on the server side, instead of using the validation partial classes at the entity level. Because the database could be updated by multiple users at different times, we should check whether there is a duplicate record only when we are ready to save changes at the server side. In the SchoolSample example, you can see similar validation logic in the function UpdateCourse(Course item) of file SchoolService.svc.cs.

For your second question, we can subscribe to the PropertyChanged event as follows:

((INotifyPropertyChanged)instructor).PropertyChanged += EntityModel_PropertyChanged;

And, you can check how they are used from the file SchoolModel.cs of project SchoolSample.Model.

Thank you very much!

Apr 3, 2012 at 6:20 PM

Fantastic. Thank you so much!