First of all I am new to .NET WCF oData DataService and I am using jQuery on the client side. I am looking for a better way (right way) to handle adding 2 different entities in one transaction (post).
Eg. I have a Parent entity with ID and Name and Child entity with ID,ParentID and Name.
I would like to add parent and get parent's id and use it to add each child. However, while adding either the parent or one of the child entity fails, then it should roll back all the transactions. One way, I thought of doing it is by creating a WebInvoke Method which would take a json string like this {"Parent":{"name":"Daddy"},"Children":[{"name":"Tom"},{"name":"Dick"},{"name":"Harry"}]} While testing I hardcoded argument in the method, on invoke everything worked fine. However, when calling POST from jQuery, the parameter comes in as NULL (annoying). I was able to send parameter to the method by passing the urlencoded json string as part of query string. However, query string has size limit and I prefere not to use it.
Question 1) Is it possible to use WebInvoke POST with parameter(s) in WCF Data Service? Question 2) Is there a better way (right way) to do what I am trying to do.
Another way of doing it (I don't like it) is to call POST on parent entity and get its ID and using it to post for each child. If one of it fails then call delete for all.