locked
Is there a recommended way to erronously stop a submit operation? RRS feed

  • Question

  • Is there a recommended way to erronously stop a submit operation? (And return the correct response to the client)

    e.g. If inside my service, I need to invalidate an entity (validation error) (And the code to do this is rather complex and best done after attaching the entity, as opposed to using attributes), how would I halt the submit process and immediately return the ChangeSet (which contains the validation error) to the client?

    Another example I can think of is if I discover -prior to saving- that my entity is in delete conflict, how do I terminate the operation and return the result immediately?

    Friday, November 9, 2012 2:04 AM

Answers

  • After running all of the CUD methods the DomainService rechecks the ChangeSet to see if any of the entities have validation errors. If any do then the Submit immediately returns the failed ChangeSet back to the client exactly as if the original validation step had failed.

    Adding a validation error looks something like:

    ChangeSetEntry changeSetEntry = this.ChangeSet.ChangeSetEntries.Where(c=>Object.RefrenceEquals(c.Entity, currentEntity)).FirstOrDefault();
    changeSetEntry.ValidationErrors = new List<ValidationResultInfo>(changeSetEntry.ValidationErrors) {new ValidationResultInfo()};


    http://www.riaservicesblog.net | RIA Services and MVVM http://bit.ly/pgL97k

    • Marked as answer by s9ilent Sunday, November 11, 2012 11:56 PM
    Friday, November 9, 2012 3:58 PM

All replies

  • After running all of the CUD methods the DomainService rechecks the ChangeSet to see if any of the entities have validation errors. If any do then the Submit immediately returns the failed ChangeSet back to the client exactly as if the original validation step had failed.

    Adding a validation error looks something like:

    ChangeSetEntry changeSetEntry = this.ChangeSet.ChangeSetEntries.Where(c=>Object.RefrenceEquals(c.Entity, currentEntity)).FirstOrDefault();
    changeSetEntry.ValidationErrors = new List<ValidationResultInfo>(changeSetEntry.ValidationErrors) {new ValidationResultInfo()};


    http://www.riaservicesblog.net | RIA Services and MVVM http://bit.ly/pgL97k

    • Marked as answer by s9ilent Sunday, November 11, 2012 11:56 PM
    Friday, November 9, 2012 3:58 PM
  • Ahh thanks, that is exactly what I was looking for. I did not know it rechecked the entries
    Sunday, November 11, 2012 11:57 PM