locked
Server Side Validation on Insert RRS feed

  • Question

  • I need to carry out a validation check that requires access to the database at the time of inserting another record. I know how to implement the custom validation but how do I only get this to work on an insert and not an update? The EntityState is always Detached, so no indication there. I am using Silverlight 3.

    Thanks

    Chris

    Wednesday, October 20, 2010 6:30 AM

Answers

  • Thanks, solved with your help in other thread.

    So in the subroutine handling the SubmittedChanges event, get the ValidationErrors returned from the ChangeSet and add the errors as ValidationSummaryItems to the DataForm. This also requires code to clear the ValidationSummary errors when changes are made.

    Friday, October 22, 2010 5:00 PM

All replies

  • Hi,

    Can you be little more clear like do you want to validate the users access with table2 while inserting values into table1 ?

    Thanks,

    Thani

     

    Wednesday, October 20, 2010 7:02 AM
  • I need to check that a record with certain criteria in Table2 does not exist before I know I can insert a record into Table1. The fact that I require data access at the time of the insert  for the validation necessitates the server-side.

    Alternatively, could I actually return validation messages by throwing a validation exception from within the DomainService subroutine that does the insert?

    Wednesday, October 20, 2010 7:12 AM
  • You could just do the validation imperitively in the insert method. If you throw a ValidationException, it will get picked up by the framework the same as if it were returned from a custom validation attribute.

    Wednesday, October 20, 2010 2:41 PM
  • When I throw a validation exception in the insert method, I get an unhandled exception after submitting when it comes back to the client.

    Wednesday, October 20, 2010 4:42 PM
  • Thanks, solved with your help in other thread.

    So in the subroutine handling the SubmittedChanges event, get the ValidationErrors returned from the ChangeSet and add the errors as ValidationSummaryItems to the DataForm. This also requires code to clear the ValidationSummary errors when changes are made.

    Friday, October 22, 2010 5:00 PM