forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 200
Adding entries with links
object edited this page Feb 12, 2013
·
17 revisions
var category = client
.From("Categories")
.InsertEntry(new
{
CategoryName = "Test3"
});
var product = client.InsertEntry("Products", new
{
ProductName = "Test4",
UnitPrice =18m,
CategoryID = category["CategoryID],
});
Assert.Equal("Test4", product["ProductName"]);
Assert.Equal(category["CategoryID"], product["CategoryID"]);
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:41:14.7420000Z</updated>
<author>
<name />
</author>
<id />
<content type="application/xml">
<m:properties>
<d:ProductName>Test4</d:ProductName>
<d:UnitPrice m:type="Edm.Decimal">18</d:UnitPrice>
<d:CategoryID m:type="Edm.Int32">10</d:CategoryID>
</m:properties>
</content>
</entry>
using Entry = System.Collections.Generic.Dictionary<string, object>;
var category = client
.For("Categories")
.InsertEntry(new
{
CategoryName = "Test5"
});
var product = client.InsertEntry("Products", new
{
ProductName = "Test6",
UnitPrice = 18m,
Category = category,
});
Assert.Equal("Test6", product["ProductName"]);
Assert.Equal(category.CategoryID, product.CategoryID);
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:43:54.5200000Z</updated>
<author>
<name />
</author>
<id />
<content type="application/xml">
<m:properties>
<d:ProductName>Test6</d:ProductName>
<d:UnitPrice m:type="Edm.Decimal">18</d:UnitPrice>
</m:properties>
</content>
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Category" type="application/atom+xml;type=Entry" title="Category" href="Categories(11)" />
</entry>
See also:
Adding entries
Linking and unlinking entries
Modifying data