Skip to content
object edited this page Feb 11, 2013 · 26 revisions

Insert a product

using Entry = System.Collections.Generic.Dictionary<string, object>;
var product = client
    .From("Products")
    .InsertEntry(new Entry() 
    { 
        { "ProductName", "Test1" }, 
        { "UnitPrice", 18m } 
    }, true);
Assert.Equal("Test1", product["ProductName"]);

Request URI: POST Products
Request content:

<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>2012-10-08T14:02:51.8990000Z</updated>
  <author>
    <name />
  </author>
  <id />
  <content type="application/xml">
    <m:properties>
      <d:ProductName>Test1</d:ProductName>
      <d:UnitPrice m:type="Edm.Decimal">18</d:UnitPrice>
    </m:properties>
  </content>
</entry>

Insert a product and validate it's autogenerated ProductID

using Entry = System.Collections.Generic.Dictionary<string, object>;
var product = client
    .From("Products")
    .InsertEntry(new Entry()
    { 
        { "ProductName", "Test1" }, 
        { "UnitPrice", 18m } 
    }, true);
Assert.True((int)product["ProductID"] > 0);

Request URI: POST Products
Request content:

<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>2012-10-08T14:02:51.8990000Z</updated>
  <author>
    <name />
  </author>
  <id />
  <content type="application/xml">
    <m:properties>
      <d:ProductName>Test1</d:ProductName>
      <d:UnitPrice m:type="Edm.Decimal">18</d:UnitPrice>
    </m:properties>
  </content>
</entry>

See also:
Adding entries with links
Modifying data

Clone this wiki locally