Export (0) Print
Expand All

Inserting and Updating Entities

Updated: August 13, 2014

To insert or update an entity, you include with the request an an OData ATOM or OData JSON entity that specifies the properties and data for the entity. For more information regarding the format of the payload see Payload Format for Table Service Operations.

The Insert Entity operation inserts a new entity with a unique primary key, formed from the combination of the PartitionKey and the RowKey. The Update Entity operation replaces an existing entity with the same PartitionKey and RowKey. The Merge Entity operation updates the properties of an existing entity, but does not replace the entity. The Insert Or Merge Entity operation creates a new entity with a unique primary key or updates the properties of an existing entity, but does not replace the entity. The Insert Or Replace Entity operation creates a new entity with a unique primary key or replaces an existing entity.

The Atom feed for an insert or update operation defines the entity's properties by specifying their names and data types, and sets the values for those properties.

The content element contains the entity's property definitions, which are specified within the m:properties element. The property's type is specified by the m:type attribute. For detailed information about property types, see Payload Format for Table Service Operations.

Here is an example of an Atom feed for an Insert Entity operation:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
  <title />
  <updated>2008-09-18T23:46:19.3857256Z<updated/>
  <author>
    <name />
  </author>
  <id />
  <content type="application/xml">
    <m:properties>
      <d:Address>Mountain View</d:Address>
      <d:Age m:type="Edm.Int32">23</d:Age>
      <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
      <d:BinaryData m:type="Edm.Binary" m:null="true" />
      <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
      <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
      <d:IsActive m:type="Edm.Boolean">true</d:IsActive>
      <d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
      <d:PartitionKey>mypartitionkey</d:PartitionKey>
      <d:RowKey>myrowkey1</d:RowKey>
      <d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
    </m:properties>
  </content>
</entry>

Note that the Atom feed for an insert or update operation must include the updated element, which is a timestamp element, as defined in the Atom Syndication Format. The updated element is specified as a string, using the current combined UTC time. Its format is as shown in the following example:

2009-03-18T04:25:03Z

For information about constructing the updated element and other DateTime values, see Formatting DateTime Property Values

To insert or update an entity using the OData JSON format, create a JSON object with property names as keys together with their property values. You may need to include the property type if it cannot be inferred through OData JSON type detection heuristics. See Payload Format for Table Service Operations for information on property type detection heuristics and on using JSON OData.

The JSON payload corresponding to the ATOM example above is as follows:

{
   "Address":"Mountain View",
   "Age":23,
   "AmountDue":200.23,
   "CustomerCode@odata.type":"Edm.Guid",
   "CustomerCode":"c9da6455-213d-42c9-9a79-3e9149a57833",
   "CustomerSince@odata.type":"Edm.DateTime",
   "CustomerSince":"2008-07-10T00:00:00",
   "IsActive":true,
   "NumOfOrders@odata.type":"Edm.Int64",
   "NumOfOrders":"255",
   "PartitionKey":"mypartitionkey",
   "RowKey":"myrowkey"
}

See Also

Show:
© 2014 Microsoft