locked
json metatag -> etag Error in ADO.NET dataservice RRS feed

  • Question

  • Hi  All,

    when i try change /update any content of the record and try to update the changes into DB[through stored procedure reference] using ajax and jquery ,  I got error.
    These data reading and content changes are doing a small Ado.net dataservice and entity framework model .

    The json object look like as follows

    {"__metadata":{"uri":"http://localhost:1029/WebDataService1.svc/products(103)","etag":"W/\"null,'Testing%20Content'\"","type":"masterModel.mari"},"content":"Testing Content","id":103,"city":"Chennai"}

    From the above, the metadata contained etag , Finally i got error messge like

    ---------------------------
    Message from webpage
    ---------------------------
    {

    "error": {

    "code": "", "message": {

    "lang": "en-US", "value": "Since entity type \'masterModel.mari\' has one or more etag properties, If-Match HTTP header must be specified for DELETE/PUT operations on this type."

    }

    }

    }
    ---------------------------
    OK  
    ---------------------------

    What was the error here? have any idea? I am using windows XP OS and iis version 5.1

    Thanks
    Mariappan .S
    Thursday, March 11, 2010 9:46 AM

Answers

  • Hi All,

     

    We can solve that like bellow , adding the header check before send the request , bellow is the sample code to avoid etag problem in ADO.net Data model.

    $.ajax({
                    type: "POST",
                    //you code function
                    etag: loadjson.__metadata.etag,             
                    dataType: "json",
                    success: function(data) {
                        alert("Update Successfully");
                    },
                    error: function(xhr) {
                        alert(xhr.responseText);
                    },
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader("If-Match", this.etag);
                    }
                });

     

    Thanks

     

    Monday, March 22, 2010 8:10 AM

All replies

  • Since the entity type has etag properties (concurrency properties), you must specify the If-Match header in the request while doing a delete or update operation ... without that header, it will be hard to figure out what version of the entity you had before you modified it.

    Hope this helps.
    Thanks
    Pratik
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, March 11, 2010 5:17 PM
    Moderator
  • Hi

    Can you give me a small example how to add this in header .

    Thanks
    Friday, March 12, 2010 7:24 AM
  • Hi All,

     

    We can solve that like bellow , adding the header check before send the request , bellow is the sample code to avoid etag problem in ADO.net Data model.

    $.ajax({
                    type: "POST",
                    //you code function
                    etag: loadjson.__metadata.etag,             
                    dataType: "json",
                    success: function(data) {
                        alert("Update Successfully");
                    },
                    error: function(xhr) {
                        alert(xhr.responseText);
                    },
                    beforeSend: function(xhr) {
                        xhr.setRequestHeader("If-Match", this.etag);
                    }
                });

     

    Thanks

     

    Monday, March 22, 2010 8:10 AM