forked from simplefx/Simple.OData
-
Notifications
You must be signed in to change notification settings - Fork 192
Linking and unlinking entries
Vagif Abilov edited this page Nov 21, 2013
·
21 revisions
Untyped syntax
var category = client .For("Categories") .Set(new { CategoryName = "Test1" }) .InsertEntry(); var product = client .For("Products") .Set(new { ProductName = "Test2" }) .InsertEntry(); client .For("Products") .Key(product) .LinkEntry("Category", category);
Typed syntax
var category = client .For<Categories>() .Set(new { CategoryName = "Test1" }) .InsertEntry(); var product = client .For<Products>() .Set(new { ProductName = "Test2" }) .InsertEntry(); client .For<Products>() .Key(product) .LinkEntry(x => x.Category, category);
Dynamic syntax
var x = ODataFilter.Expression; var category = client .For(x.Categories) .Set(x.CategoryName = "Test1") .InsertEntry(); var product = client .For(x.Products) .Set(x.ProductName = "Test2") .InsertEntry(); client .For(x.Products) .Key(product) .LinkEntry(x.Category, category);
Request URI: PUT Products(79)/$links/Category
Request content:
<uri xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">Categories(10)</uri>
Untyped syntax
var category = client .For("Categories") .Set(new { CategoryName = "Test1" }) .InsertEntry(); var product = client .For("Products") .Set(new { ProductName = "Test2", CategoryID = 1 }) .InsertEntry(); client .For("Products") .Key(product) .LinkEntry("Category", category);
Typed syntax
var category = client .For<Categories>() .Set(new { CategoryName = "Test1" }) .InsertEntry(); var product = client .For<Products>() .Set(new { ProductName = "Test2", CategoryID = 1 }) .InsertEntry(); client .For<Products>() .Key(product) .LinkEntry(x => x.Category, category);
Dynamic syntax
var x = ODataFilter.Expression; var category = client .For(x.Categories) .Set(x.CategoryName = "Test1") .InsertEntry(); var product = client .For(x.Products) .Set(x.ProductName = "Test2", x.CategoryID = 1) .InsertEntry(); client .For(x.Products) .Key(product) .LinkEntry(x.Category, category);
Request URI: PUT Products(80)/$links/Category
Request content:
<uri xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">Categories(11)</uri>
Untyped syntax
var category = client .For("Categories") .Set(new { CategoryName = "Test6" }) .InsertEntry(); var product = client .For("Products") .Set(new { ProductName = "Test7", Category = category }) .InsertEntry(); client .For("Products") .Key(product) .UnlinkEntry("Category");
Typed syntax
var category = client .For<Categories>() .Set(new { CategoryName = "Test6" }) .InsertEntry(); var product = client .For<Products>() .Set(new { ProductName = "Test7", Category = category }) .InsertEntry(); client .For<Products>() .Key(product) .UnlinkEntry(x => x.Category);
Dynamic syntax
var x = ODataFilter.Expression; var category = client .For(x.Categories) .Set(x.CategoryName = "Test6") .InsertEntry(); var product = client .For(x.Products) .Set(x.ProductName = "Test7", x.Category = category) .InsertEntry(); client .For(x.Products) .Key(product) .UnlinkEntry(x.Category);
Request URI: DELETE Products(81)/$links/Category
Untyped syntax
var category = client .For("Categories") .Set(new { CategoryName = "Test3" }) .InsertEntry(); var product1 = client .For("Products") .Set(new { ProductName = "Test4", UnitPrice = 21m, CategoryID = 1 }) .InsertEntry(); var product2 = client .For("Products") .Set(new { ProductName = "Test5", UnitPrice = 22m, CategoryID = 1 }) .InsertEntry(); client .For("Categories") .Key(category) .LinkEntry("Products", new[] { product1, product2 });
Typed syntax
var category = client .For<Categories>() .Set(new { CategoryName = "Test3" }) .InsertEntry(); var product1 = client .For<Products>() .Set(new { ProductName = "Test4", UnitPrice = 21m, CategoryID = 1 }) .InsertEntry(); var product2 = client .For<Products>() .Set(new { ProductName = "Test5", UnitPrice = 22m, CategoryID = 1 }) .InsertEntry(); client .For<Categories>() .Key(category) .LinkEntry(x => x.Products, new[] { product1, product2 });
Dynamic syntax
var x = ODataFilter.Expression; var category = client .For(x.Categories) .Set(x.CategoryName = "Test3") .InsertEntry(); var product1 = client .For(x.Products) .Set(x.ProductName = "Test4", x.UnitPrice = 21m, x.CategoryID = 1) .InsertEntry(); var product2 = client .For("Products") .Set(x.ProductName = "Test5", x.UnitPrice = 22m, x.CategoryID = 1) .InsertEntry(); client .For("Categories") .Key(category) .LinkEntry(x.Products, new[] { product1, product2 });
Request URI: MERGE Categories(13)/$links/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-15T14:45:21.7200000Z</updated> <author> <name /> </author> <id /> <content type="application/xml"> <m:properties /> </content> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" type="application/atom+xml;type=Entry" title="Products" href="Products(110)" /> <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Products" type="application/atom+xml;type=Entry" title="Products" href="Products(111)" /> </entry>
See also:
Adding entries with links
Updating entries with links
Modifying data