WCF ODATA: SaveChanges() does not return modified entity

4 posts, 0 answers
  1. Samuel
    Samuel avatar
    13 posts
    Member since:
    Aug 2013

    Posted 03 Sep 2013 Link to this post

    I use WCF ODATA to communicate with my JavaScript client. 
    
    When I do an update operation, the SaveChanges method is called. 

    The problem is that I also use a ChangeInterceptor for setting a property value on my entity before saving to DB.

    Now the problem is that the SaveChanges method returns void. It would be great if it could return the actual saved entity 
    instead so that the client is aware of changes made by the server.

    Am I missing something and this is already possible ? Or would that be a change request ? 

    Thanks EDIT: When an new entity is inserted, it is actually returned by the server. Only updated entities are not returned. See the response of the $batch call for an insert:
    --batchresponse_7aa4983b-fa44-4254-9013-897f986679ea
    Content-Type: multipart/mixed; boundary=changesetresponse_27433a38-8952-42d8-b66b-fb7a27406c90
     
    --changesetresponse_27433a38-8952-42d8-b66b-fb7a27406c90
    Content-Type: application/http
    Content-Transfer-Encoding: binary
     
    HTTP/1.1 201 Created
    DataServiceVersion: 3.0;
    Content-Type: application/json;odata=fullmetadata;streaming=true;charset=utf-8
    Content-ID: 1
    X-Content-Type-Options: nosniff
    Cache-Control: no-cache
    Location: http://localhost:24497/DirectDebitModelService.svc/Mandates(48)
     
    {"odata.metadata":"http://localhost:24497/DirectDebitModelService.svc/$metadata#Mandates/@Element","odata.type":"DirectDebitModel.Mandate","odata.id":"http://localhost:24497/DirectDebitModelService.svc/Mandates(48)","odata.editLink":"Mandates(48)","OpenPositions@odata.navigationLinkUrl":"Mandates(48)/OpenPositions","AccountOwnerName":"berthelots","AccountOwnerTiersId":225956,"Amendment":0,"BIC":"BCLLLULL","CreatedBy":"berthelots","CreatedDate@odata.type":"Edm.DateTime","CreatedDate":"2013-09-03T10:41:08.697","CreditorType":0,"IBAN":"LU521111000011110000","Id":48,"IsSEPAMandate":false,"MandateReference":"001/257000004","MandateType":0,"NextSequenceType":0,"OldCetrelReference":null,"PlaceOfSignature":null,"PolicyNumber":"257000004","Remarks":null,"RowVersion@odata.type":"Edm.Int64","RowVersion":"6020","SignatureDate":null,"Status":1,"UpdatedBy":null,"UpdatedDate":null}
    --changesetresponse_27433a38-8952-42d8-b66b-fb7a27406c90--
    --batchresponse_7aa4983b-fa44-4254-9013-897f986679ea--
    and the response of the $batch call for an update. Notice that the data is not returned this time:
    --batchresponse_5988bacc-ea77-43e8-8fe7-f18fe30ce710
    Content-Type: multipart/mixed; boundary=changesetresponse_b5c2d17b-f7cd-42a2-a56c-e8fbbdade4ae
     
    --changesetresponse_b5c2d17b-f7cd-42a2-a56c-e8fbbdade4ae
    Content-Type: application/http
    Content-Transfer-Encoding: binary
     
    HTTP/1.1 204 No Content
    Content-ID: 1
    X-Content-Type-Options: nosniff
    Cache-Control: no-cache
    DataServiceVersion: 1.0;
     
     
    --changesetresponse_b5c2d17b-f7cd-42a2-a56c-e8fbbdade4ae--
    --batchresponse_5988bacc-ea77-43e8-8fe7-f18fe30ce710--


  2. Samuel
    Samuel avatar
    13 posts
    Member since:
    Aug 2013

    Posted 04 Sep 2013 Link to this post

    Prefer Header was the answer.

    see  http://msdn.microsoft.com/en-us/library/gg602811(v=vs.103).aspx. Under "Setting the Prefer Header for Change Operations",
  3. DevCraft banner
  4. Dimitar Tachev
    Admin
    Dimitar Tachev avatar
    67 posts

    Posted 06 Sep 2013 Link to this post

    Hello Samuel,

     
    I am glad that you have found a solution to your problem.

    The SaveChanges method of the OpenAccessContext does not have a return value because it is committing the current transaction which can contains a lot of insert, update and delete operations and we cannot calculate a useful return value.

    In order to track the changes that are committed during your SaveChanges method calls you could take advantage of our GetChanges method. You could find a detailed description of this approach in our How to Get Changes that Will be Performed During the Next Commit documentation section.

    If you need further information about the OpenAccess ORM transaction methods, you could take a look the Handling Transactions documentation article.

    I hope this helps. Do not hesitate to contact us back if you need any further assistance.

    Regards,
    Dimitar Tachev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  5. Samuel
    Samuel avatar
    13 posts
    Member since:
    Aug 2013

    Posted 06 Sep 2013 Link to this post

    Well actually the solution I've found does not work with OpenAccess Data Service. It should, but for some reasons the service ignores the header and does not return the modified entity.

    I'll take a look at your links.
Back to Top