forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 199
Adding entries
glenfisk edited this page Apr 7, 2022
·
26 revisions
var product = await client
.For("Products")
.Set(new { ProductName = "Test1", UnitPrice = 18m })
.InsertEntryAsync();
Assert.Equal("Test1", product["ProductName"]);
var product = await client
.For<Products>()
.Set(new { ProductName = "Test1", UnitPrice = 18m })
.InsertEntryAsync();
Assert.Equal("Test1", product.ProductName);
var x = ODataDynamic.Expression;
var product = await client
.For(x.Products)
.Set(x.ProductName = "Test1", x.UnitPrice = 18m)
.InsertEntryAsync();
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>
var product = await client
.For("Products")
.Set(new { ProductName = "Test1", UnitPrice = 18m })
.InsertEntryAsync();
Assert.True((int)product["ProductID"] > 0);
var product = await client
.For<Products>()
.Set(new { ProductName = "Test1", UnitPrice = 18m })
.InsertEntryAsync();
Assert.True((int)product["ProductID"] > 0);
var x = ODataDynamic.Expression;
var product = await client
.For(x.Products)
.Set(x.ProductName = "Test1", x.UnitPrice = 18m)
.InsertEntryAsync();
Assert.True(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