<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>leohu</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/leohu/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/leohu/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 04:21:36 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>webapi 2.2 and T4 release announcement</title>
      <link>https://docs.microsoft.com/archive/blogs/leohu/webapi-2-2-and-t4-release-announcement</link>
      <pubDate>Thu, 13 Mar 2014 23:43:23 GMT</pubDate>
      <dc:creator><![CDATA[LeoHu1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/leohu/2014/03/13/webapi-2-2-and-t4-release-announcement/</guid>
      <description><![CDATA[I am very excited to announce the availability of nightly builds on MyGet for ASP.NET Web API 2.2...]]></description>
      <content:encoded><![CDATA[<p>I am very excited to announce the availability of nightly builds on MyGet for ASP.NET Web API 2.2 for OData v4.0 along with T4 template support for writing OData v4 clients. The Web API 2.2 release is particularly noteworthy as it is the first Web API release with support for OData v4 with selected highly demanded features. For a summary of what’s new in OData v4.0, please visit <a href="https://microsoft.sharepoint.com/teams/odata/SitePages/What%27s%20New%20in%20OData%20v4.aspx">What’s New in OData v4</a>.</p>  <h1>What’s New in ASP.NET Web API 2.2 for OData v4.0</h1>  <p>&#160;</p>  <h3>New features</h3>  <p><font size="3"><b>1.</b><b> Protocol and format changes from V3 to V4.</b></font></p>  <p><font size="3"><b>2.</b><b> OData attribute routing: </b>This release allows you to define the routes in your controllers and actions using attributes.<b></b></font></p>  <p><font size="3"><b>3.</b><b> Support for functions: </b>This release allows you to define functions in your OData model and bind them to actions in your controller that implement them.<b></b></font></p>  <p><font size="3"><b>4.</b><b> Model aliasing:</b> This release allows to change the names of the types and properties in your OData model to be different than the ones in your CLR types.<b></b></font></p>  <p><font size="3"><b>5.</b><b> Support for limiting allowed queries:</b> This feature release the service to define limitations on the properties of the model that can be filtered, sorted, expanded or navigated across.<b></b></font></p>  <p><font size="3"><b>6.</b><b> Support for ETags: </b>This release allows to generate an @odata.etag annotation based on some properties of the entity that can be used in IfMatch and IfNoneMatch headers in following requests.<b></b></font></p>  <p><font size="3"><b>7.</b><b> Support for Enums:</b> Improved our support for Enums and now we support them as OData enumerations.<b></b></font></p>  <p><font size="3"><b>8.</b><b> Support for $format: </b>Added support for $format, so clients are able to specify the desired format of the response in the URL.</font></p>  <p>&#160;</p>  <p><b></b></p>  <p><b></b></p>  <h3>Where to get it</h3>  <p><font size="3">It is now available at </font><a href="https://www.myget.org/gallery/aspnetwebstacknightly"><font size="3">ASP.NET Web API 2.2 for OData v4.0</font></a><font size="3"> on MyGet. We recommend version v5.2.0-alpha1-140307 as a good place to start kicking the tires or go ahead and try the latest greatest. Please refer to the instructions on how to </font><a href="https://aspnetwebstack.codeplex.com/wikipage?title=Use%20Nightly%20Builds"><font size="3">use nightly builds</font></a><font size="3"> on our CodePlex site. </font></p>  <p>&#160;</p>  <h4></h4>  <h3>Sample codes</h3>  <p><font size="3">We have provided a comprehensive list of OData v4.0 service samples to accelerate your own v4.0 service implementation. They are available at </font><a href="https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/"><font size="3">https://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/</font></a></p>  <p>&#160;</p>  <h4></h4>  <h3>Tutorial Blog</h3>  <p><a href="http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx"><font size="3">http://blogs.msdn.com/b/webdev/archive/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0.aspx</font></a></p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <p>&#160;</p>  <h1>T4 Template to Support V4 OData Spec</h1>  <p>&#160;</p>  <h4><b></b></h4>  <h3>New Features</h3>  <p><font size="3"><b>1. </b><b>OData 4.0 Spec</b>:&#160; This release is able to generate C# and VB .NET client-side proxy classes to consume a OData V4 service.</font></p>  <p><font size="3"><b>2. </b><b>Enum Support:&#160; </b>This release supports generating the codes of enum values and properties for OData Client library.<b></b></font></p>  <p><font size="3"><b>3. </b><b>Singleton Support:</b>&#160; This release supports generating the codes of singleton values. You could now compose a LINQ query using singletons values.</font></p>  <h4></h4>  <h3>Platform</h3>  <p><font size="3">We support the Professional, Premium, and Ultimate versions of Visual Studio 2010, 2012, 2013.</font></p>  <h3>Where to get it</h3>  <p><a href="http://visualstudiogallery.msdn.microsoft.com/9b786c0e-79d1-4a50-89a5-125e57475937"><font size="3">http://visualstudiogallery.msdn.microsoft.com/9b786c0e-79d1-4a50-89a5-125e57475937</font></a></p>  <h3>Blog and Tutorial</h3>  <p><a href="http://blogs.msdn.com/b/odatateam/archive/2014/03/11/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx"><font size="3">http://blogs.msdn.com/b/odatateam/archive/2014/03/11/how-to-use-odata-client-code-generator-to-generate-client-side-proxy-class.aspx</font></a></p>  <h1>Call to Action</h1>  <h4><b></b></h4>  <p><font size="3">If you has an existing OData service or is considering adding an OData service or migrating your V3 service to V4, now is an excellent time to engage with us. </font></p>]]></content:encoded>
    </item>
    <item>
      <title>Typeless Entity Object Support in WebApi</title>
      <link>https://docs.microsoft.com/archive/blogs/leohu/typeless-entity-object-support-in-webapi</link>
      <pubDate>Mon, 04 Nov 2013 19:47:00 GMT</pubDate>
      <dc:creator><![CDATA[LeoHu1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/leohu/2013/11/04/typeless-entity-object-support-in-webapi/</guid>
      <description><![CDATA[The Problem
In current WebApi impl you will be using an ODataMobuilder or...]]></description>
      <content:encoded><![CDATA[<h1>The Problem</h1>
<p>In current WebApi impl you will be using an <strong>ODataMobuilder</strong> or <strong>ODataConventionModelBuilder</strong> to setup your model for oData feed. <strong>ODataConventionModelBuilder</strong> is the preferred way as it&rsquo;d automatically map CLR classes to an EDM model based on a set of predefined Conventions.</p>
<p>For example you have class product and will be writing below code to setup your product model:<span style="font-size: 12px;">&nbsp;</span></p>
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> Product<br />{<br />        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> ID { get; set; }<br /><br />        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> Name { get; set; }<br /><br />        <span style="color: #0000ff;">public</span> DateTime? ReleaseDate { get; set; }<br /><br />        <span style="color: #0000ff;">public</span> DateTime? SupportedUntil { get; set; }<br /><br />        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">virtual</span> ProductFamily Family { get; set; }<br />}<br />ODataConventionModelBuilder builder = <span style="color: #0000ff;">new</span> ODataConventionModelBuilder();<br />builder.EntitySet&lt;Product&gt;(<span style="color: #006080;">"Products"</span>);  </pre>
<p>&nbsp;</p>
<p><span style="font-size: 12px;">The problem with both current model builder that is that it requires a strong CLR type (Product in above code snippet) for each and every EDM type that the service is exposing. The mapping between the CLR type and the EDM type is one-to-one and not configurable.</span></p>
<p>To address that we introduced a set of new interfaces and classes that will be discussed below to support building entity object without backing CLR type. This is quite handy in the scenarios where the model is built in runtime. For example your data model will be matching a database schedule that is only discoverable when you load it, and all the payload is from the tables in that database.</p>
<h1>Typeless Impl Internals</h1>
<p>There are 4 key interfaces defined to enable the typeless feature. <strong>IEdmObject</strong>, <strong>IEdmStructuredObject</strong>, <strong>IEdmEntityObject</strong> and <strong>IEdmComplexObject</strong>. See below diagram for their inheritance relationship.</p>
<p><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/68/metablogapi/5164.clip_image002_389C9347.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-61-68-metablogapi/5164.clip_5F00_image002_5F00_389C9347.jpg"><img style="background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border-width: 0px;" title="clip_image002" src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/68/metablogapi/3060.clip_image002_thumb_0E6CE55F.jpg" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-61-68-metablogapi/3060.clip_5F00_image002_5F00_thumb_5F00_0E6CE55F.jpg" alt="clip_image002" width="244" height="158" border="0" /></a></p>
<p>&nbsp;</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; height: 279px; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; height: 297px; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IEdmObject<br />{<br />        IEdmTypeReference GetEdmType();<br />}<br /><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">interface</span> IEdmStructuredObject : IEdmObject<br />{<br />        <span style="color: #0000ff;">bool</span> TryGetPropertyValue(<span style="color: #0000ff;">string</span> propertyName, <span style="color: #0000ff;">out</span> <span style="color: #0000ff;">object</span> <span style="color: #0000ff;">value</span>);<br />}<br /><br />The classes EdmEntityObject, EdmComplexObject, EdmEntityCollectionObject, EdmComplexCollectionObject are created to impl above interfaces to model a typeless <span style="color: #0000ff;">object</span> system. <br /><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> EdmEntityObject : EdmStructuredObject, IEdmEntityObject<br />{&hellip; &hellip;}<br /><br /><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">abstract</span> <span style="color: #0000ff;">class</span> EdmStructuredObject : Delta, IEdmStructuredObject<br />{&hellip; &hellip;}</pre>
</div>
<p>&nbsp;</p>
<p>(Delta inheritance enables the <strong>EdmEntityObject</strong> the ability to track a set of changes for an entity object, you will be using that in a patch scenario)</p>
<p>Let&rsquo;s take a look at the default implementation of the function <strong>TryGetPropertyValue</strong>/<strong>TrySetPropertyValue</strong> for <strong>EdmEntityObject</strong> and <strong>EdmStructuredObject</strong></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">override</span> <span style="color: #0000ff;">bool</span> TryGetPropertyValue(<span style="color: #0000ff;">string</span> name, <span style="color: #0000ff;">out</span> <span style="color: #0000ff;">object</span> <span style="color: #0000ff;">value</span>)<br />{<br />    IEdmProperty property = _actualEdmType.FindProperty(name);<br />    <span style="color: #0000ff;">if</span> (property != <span style="color: #0000ff;">null</span>)<br />    {<br />        <span style="color: #0000ff;">if</span> (_container.ContainsKey(name))<br />        {<br />            <span style="color: #0000ff;">value</span> = _container[name];<br />            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;<br />        }<br />        <span style="color: #0000ff;">else</span><br />        {<br />            <span style="color: #0000ff;">value</span> = GetDefaultValue(property.Type);<br />            <span style="color: #008000;">// store the default value (but don't update the list of 'set properties').</span><br />            _container[name] = <span style="color: #0000ff;">value</span>;<br />            <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span>;<br />        }<br />    }<br />    <span style="color: #0000ff;">else</span><br />    {<br />        <span style="color: #0000ff;">value</span> = <span style="color: #0000ff;">null</span>;<br />        <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span>;<br />    }<br />}<br /><br /></pre>
</div>
<p>&nbsp;<span style="font-size: 12px;">The code itself is pretty straightforward in that</span></p>
<p>1) It uses <strong>actualEdmType</strong> to record the type info for a property.</p>
<p>2) A Dictionary container is used to record the actual property value.</p>
<p>3) The class also provides many other helper functions, for example to locate a property by type and etc.</p>
<p>Lets create an example to learn how to setup and use a model without strong CLR type in ASP.NET Web API. To put the example as simple as possible. Let&rsquo;s assume:</p>
<p>1) You already loaded the scheme from any sql connection and knew type info of the column properties.</p>
<p>2) There are only 2 associated tables in the DB. Product table and category table in a one to many relationship, which means a product can only have 0 to 1 category and a category can have multiple products in it.</p>
<p>&nbsp;<span style="font-size: 2em;">Create the Model</span></p>
<p>First we need to setup the EDM model for product and category and their associations.</p>
<div class="csharpcode">
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><br />        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> IEdmModel GetEdmModel()<br />        {<br />            EdmModel model = <span style="color: #0000ff;">new</span> EdmModel();<br /><br />            <span style="color: #008000;">// create &amp; add entity type to the model.</span><br />            EdmEntityType product = <span style="color: #0000ff;">new</span> EdmEntityType(<span style="color: #006080;">"Org.Microsoft"</span>, <span style="color: #006080;">"Product"</span>);<br />            product.AddStructuralProperty(<span style="color: #006080;">"Name"</span>, EdmPrimitiveTypeKind.String);<br />            product.AddStructuralProperty(<span style="color: #006080;">"Price"</span>, EdmPrimitiveTypeKind.Double);<br />            var key = product.AddStructuralProperty(<span style="color: #006080;">"ID"</span>, EdmPrimitiveTypeKind.Int32);<br />            product.AddKeys(key);<br />            model.AddElement(product);<br /><br />            EdmEntityType category = <span style="color: #0000ff;">new</span> EdmEntityType(<span style="color: #006080;">"Org.Microsoft"</span>, <span style="color: #006080;">"Category"</span>);<br />            category.AddStructuralProperty(<span style="color: #006080;">"Name"</span>, EdmPrimitiveTypeKind.String);<br />            var key1 = category.AddStructuralProperty(<span style="color: #006080;">"ID"</span>, EdmPrimitiveTypeKind.Int32);<br />            category.AddKeys(key1);<br />            model.AddElement(category);<br /><br />            <span style="color: #008000;">// setup navigations</span><br /><br />            EdmNavigationPropertyInfo infoFrom = <span style="color: #0000ff;">new</span> EdmNavigationPropertyInfo();<br />            infoFrom.Name = <span style="color: #006080;">"Product"</span>;<br />            infoFrom.TargetMultiplicity = EdmMultiplicity.Many;<br />            infoFrom.Target = product <span style="color: #0000ff;">as</span> IEdmEntityType;<br /><br />            EdmNavigationPropertyInfo infoTo = <span style="color: #0000ff;">new</span> EdmNavigationPropertyInfo();<br />            infoFrom.Name = <span style="color: #006080;">"Category"</span>;<br />            infoFrom.TargetMultiplicity = EdmMultiplicity.One;<br />            infoFrom.Target = category <span style="color: #0000ff;">as</span> IEdmEntityType;<br /><br />            EdmNavigationProperty productCategory = product.AddBidirectionalNavigation(infoFrom, infoTo);<br /><br />            <span style="color: #008000;">// create &amp; add entity container to the model.</span><br />            EdmEntityContainer container = <span style="color: #0000ff;">new</span> EdmEntityContainer(<span style="color: #006080;">"Org.Microsoft"</span>, <span style="color: #006080;">"ProductsService"</span>);<br />            model.AddElement(container);<br />            model.SetIsDefaultEntityContainer(container, isDefaultContainer: <span style="color: #0000ff;">true</span>); <span style="color: #008000;">// set this as the default container for smaller json light links.</span><br /><br />            <span style="color: #008000;">// create &amp; add entity set 'Products'.</span><br />            EdmEntitySet Products = container.AddEntitySet(<span style="color: #006080;">"Products"</span>, product);<br />            EdmEntitySet Categories = container.AddEntitySet(<span style="color: #006080;">"Caegories"</span>, category);<br />            Products.AddNavigationTarget(productCategory, Categories);<br />            <span style="color: #0000ff;">return</span> model;<br />        }</pre>
</div>
</div>
<p>&nbsp;</p>
<h1>Add a Simple Controller</h1>
<p>Again for simplicity reason let&rsquo;s build a controller that maps every request to a <strong>SimpleController</strong>.</p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span> SelectController(ODataPath odataPath, HttpRequestMessage request)<br />{<br />    Console.WriteLine(odataPath.PathTemplate);<br />    ODataPathSegment firstSegment = odataPath.Segments.FirstOrDefault();<br /><br />    <span style="color: #0000ff;">if</span> (firstSegment != <span style="color: #0000ff;">null</span> &amp;&amp; firstSegment <span style="color: #0000ff;">is</span> EntitySetPathSegment)<br />    {<br />        <span style="color: #0000ff;">return</span> <span style="color: #006080;">"Simple"</span>;<br />    }<br /><br />    <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span>;<br />}</pre>
</div>
<p>&nbsp;</p>
<h1>Response Handler</h1>
<p>Lets built 3 handlers to impl 3 scenarios</p>
<p>1) Get product by ID. By sending GET request <a href="http://localhost/odata/Products">http://localhost/odata/Products</a></p>
<div class="csharpcode">
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> EdmEntityObjectCollection Get()<br />{<br />            ODataPath path = Request.GetODataPath();<br />            IEdmType edmType = path.EdmType;<br />            Contract.Assert(edmType.TypeKind == EdmTypeKind.Collection, <span style="color: #006080;">"we are serving get {entityset}"</span>);<br /><br />            IEdmEntityTypeReference entityType = (edmType <span style="color: #0000ff;">as</span> IEdmCollectionType).ElementType.AsEntity();<br /><br />            var collectionProduct = <span style="color: #0000ff;">new</span> EdmEntityObjectCollection(<span style="color: #0000ff;">new</span> EdmCollectionTypeReference(edmType <span style="color: #0000ff;">as</span> IEdmCollectionType, isNullable: <span style="color: #0000ff;">false</span>));<br /><br />            var entityProduct = <span style="color: #0000ff;">new</span> EdmEntityObject(entityType);<br />            entityProduct.TrySetPropertyValue(<span style="color: #006080;">"Name"</span>, <span style="color: #006080;">"Microsoft Windows"</span>);<br />            entityProduct.TrySetPropertyValue(<span style="color: #006080;">"Price"</span>, 99.99);<br />            entityProduct.TrySetPropertyValue(<span style="color: #006080;">"ID"</span>, 12345);<br /><br />            var entityCategory = <span style="color: #0000ff;">new</span> EdmEntityObject(entityType);<br />            entityCategory.TrySetPropertyValue(<span style="color: #006080;">"Name"</span>, <span style="color: #006080;">"Category 1"</span>);<br />            entityCategory.TrySetPropertyValue(<span style="color: #006080;">"ID"</span>, 10000);<br /><br />            entityProduct.TrySetPropertyValue(<span style="color: #006080;">"Category"</span>, entityCategory);<br />            collectionProduct.Add(entityProduct);<br />            <span style="color: #0000ff;">return</span> collectionProduct;<br />}</pre>
</div>
</div>
<p>&nbsp;</p>
<p>2) Get the category of given product by sending GET request <a href="http://localhost/odata/Products(12345)/Category">http://localhost/odata/Products(12345)/Category</a></p>
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> IEdmEntityObject GetCategory(<span style="color: #0000ff;">string</span> key)<br />{<br />    ODataPath path = Request.GetODataPath();<br />    IEdmEntityType entityType = path.EdmType <span style="color: #0000ff;">as</span> IEdmEntityType;<br /><br />    var entity = <span style="color: #0000ff;">new</span> EdmEntityObject(entityType);<br />    entity.TrySetPropertyValue(<span style="color: #006080;">"Name"</span>, <span style="color: #006080;">"Category 1"</span>);<br />    entity.TrySetPropertyValue(<span style="color: #006080;">"ID"</span>, 10000);<br />    <span style="color: #0000ff;">return</span> entity;<br />}</pre>
</div>
<p>The key to compose the payload is to create EdmEntityObject and populate the properties by using TrySetPropertyValue() interface.</p>
<p>3) Post a new product entity to the control by sending</p>
<p>On the client side we do:</p>
<p>&nbsp;<span style="font-size: 12px; background-color: #f4f4f4; line-height: 12pt;">var request = </span><span style="color: #0000ff;">new</span><span style="font-size: 12px; background-color: #f4f4f4; line-height: 12pt;"> HttpRequestMessage(HttpMethod.Post, </span><span style="color: #006080;">"http://localhost/odata/Products"</span><span style="font-size: 12px; background-color: #f4f4f4; line-height: 12pt;">);</span></p>
<div class="csharpcode">
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;">request.Content = <span style="color: #0000ff;">new</span> StringContent(<span style="color: #006080;">"{ 'Name': 'leo', Price : 1.99, ID: 12345}"</span>, Encoding.Default, <span style="color: #006080;">"application/json"</span>);<br />PrintResponse(client.SendAsync(request).Result);</pre>
</div>
<pre><span style="font-size: 12px;">In the post handler we do to deserialize an </span><strong style="font-size: 12px;">IdmEntityObject</strong></pre>
</div>
<div class="csharpcode">
<div id="codeSnippetWrapper" style="overflow: auto; cursor: text; font-size: 8pt; font-family: 'Courier New', courier, monospace; direction: ltr; text-align: left; margin: 20px 0px 10px; line-height: 12pt; max-height: 200px; width: 97.5%; background-color: #f4f4f4; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="overflow: visible; font-size: 8pt; font-family: 'Courier New', courier, monospace; color: black; direction: ltr; text-align: left; margin: 0em; line-height: 12pt; width: 100%; background-color: #f4f4f4; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> HttpResponseMessage Post(IEdmEntityObject entity)<br />{<br />    ODataPath path = Request.GetODataPath();<br />    IEdmType edmType = path.EdmType;<br />    Contract.Assert(edmType.TypeKind == EdmTypeKind.Collection, <span style="color: #006080;">"we are serving POST {entityset}"</span>);<br /><br />    IEdmEntityTypeReference entityType = (edmType <span style="color: #0000ff;">as</span> IEdmCollectionType).ElementType.AsEntity();<br /><br />    <span style="color: #008000;">// do something with the entity object here.</span><br /><br />    <span style="color: #0000ff;">return</span> Request.CreateResponse(HttpStatusCode.Created, entity);<br /> }</pre>
</div>
<pre><span style="font-size: 12px;">&nbsp;</span></pre>
</div>
<h1>Summary</h1>
<p>The new feature of the <strong>IEdmEntityObject</strong> that ships in oData version 5.0 adds support for creating an entity model object without strong CLR type backing. This provides better integration ability with your existing data model regardless your data type and source.</p>]]></content:encoded>
    </item>
    <item>
      <title>oData and JSON payload examples</title>
      <link>https://docs.microsoft.com/archive/blogs/leohu/odata-and-json-payload-examples</link>
      <pubDate>Fri, 04 Oct 2013 14:08:00 GMT</pubDate>
      <dc:creator><![CDATA[LeoHu1]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/leohu/2013/10/04/odata-and-json-payload-examples/</guid>
      <description><![CDATA[oData and JSON Format

The Open Data Protocol (OData) is a data access protocol built on core...]]></description>
      <content:encoded><![CDATA[<div>
<h1>oData and JSON Format</h1>
</div>
<p>The Open Data Protocol (OData) is a data access protocol built on core protocols like HTTP and commonly accepted methodologies like REST for the web. OData provides a uniform way to query and manipulate data sets through CRUD operations (create, read, update, and delete).</p>
<p>JSON&nbsp;is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a text format that is completely language independent. JSON is built on a collection of name/value pairs realized in most modern languages.</p>
<p>OData&rsquo;s JSON format extends JSON by defining a set of canonical annotations for control information such as ids, types, and links, and custom annotations MAY be used to add domain-specific information to the payload.</p>
<p>&nbsp;</p>
<p>A key feature of OData&rsquo;s JSON format is to allow omitting predictable parts of the wire format from the actual payload. Expressions are used to compute missing links, type information, and other control data on client side. Annotations are used in JSON to capture control information that cannot be predicted (e.g., the next link of a collection of entities) as well as a mechanism to provide values where a computed value would be wrong (e.g., if the media read link of one particular entity does not follow the standard URL conventions).</p>
<p>&nbsp;</p>
<p>Computing values from metadata expressions on client side could be very expense. To accommodate for this the&nbsp;Accept&nbsp;header allows the client to control the amount of control information added to the response.</p>
<p>This doc is aiming to provide a quick overview of what&rsquo;s the JSON payload would be look like in various typical scenarios.</p>
<p>&nbsp;</p>
<div>
<h1>Data model Used for the Sample</h1>
</div>
<p>We use the&nbsp;Northwind&nbsp;database as the SQL sample database in all our JSON examples. Northwind is a fictitious company that imports and exports foods globally.&nbsp;The Northwind sample database provides a good database structure&nbsp;for our JSON experiment.</p>
<p>Please see <a href="http://msdn.microsoft.com/en-us/library/ms227484(v=vs.80).aspx">http://msdn.microsoft.com/en-us/library/ms227484(v=vs.80).aspx</a> to get instructions of how to setup the database with your sqlserver</p>
<p>The following database diagram illustrates the Northwind database structure:</p>
<p>&nbsp;<a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/68/6644.d.png" original-url="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-61-68/6644.d.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/61/68/6644.d.png" original-url="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-61-68/6644.d.png" alt="" border="0" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<h1>Response payload samples</h1>
</div>
<p>This section provides JSON samples of response payloads for the payload kinds supported in OData. The samples are based on a northwind domain.</p>
<h2>Read an EntitySet</h2>
<p><a href="http://services.odata.org/V3/OData/OData.svc/Products?$format=json">http://services.odata.org/V3/OData/OData.svc/Products?$format=json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#Products">http://services.odata.org/V3/OData/OData.svc/$metadata#Products</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"value"</strong>:[<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Bread",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Whole&nbsp;grain&nbsp;bread",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"1992-01-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:4,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"2.5"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:1,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Milk",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Low&nbsp;fat&nbsp;milk",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"1995-10-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:3,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"3.5"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:2,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Vint&nbsp;soda",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Americana&nbsp;Variety&nbsp;-&nbsp;Mix&nbsp;of&nbsp;6&nbsp;flavors",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"2000-10-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:3,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"20.9"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&hellip;<br /> &nbsp;&nbsp;&nbsp;]<br /> }</p>
<h2>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>Read an Entity</h2>
<p><a href="http://services.odata.org/V3/OData/OData.svc/Products(2)?$format=json">http://services.odata.org/V3/OData/OData.svc/Products(2)?$format=json</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#Products/@Element">http://services.odata.org/V3/OData/OData.svc/$metadata#Products/@Element</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:2,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Vint&nbsp;soda",<br /> &nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Americana&nbsp;Variety&nbsp;-&nbsp;Mix&nbsp;of&nbsp;6&nbsp;flavors",<br /> &nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"2000-10-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:3,<br /> &nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"20.9"<br /> }</p>
<h2>&nbsp;</h2>
<h2>Read Property</h2>
<h2>&nbsp;</h2>
<p><a href="http://services.odata.org/V3/OData/OData.svc/Products(2)/Description?$format=json">http://services.odata.org/V3/OData/OData.svc/Products(2)/Description?$format=json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#Edm.String">http://services.odata.org/V3/OData/OData.svc/$metadata#Edm.String</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"value"</strong>:"Americana&nbsp;Variety&nbsp;-&nbsp;Mix&nbsp;of&nbsp;6&nbsp;flavors"<br /> }</p>
<p>&nbsp;</p>
<p><a href="http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Name?$format=application/json">http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Name?$format=application/json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Edm.String">http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Edm.String</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"value"</strong>:"Bread"<br /> }</p>
<h2>&nbsp;</h2>
<h2>&nbsp;</h2>
<h2>Remove an Entity</h2>
<p>&nbsp;</p>
<p>DELETE http://services.odata.org/V3/(S(ettihtez1pypsghekhjamb1u))/OData/OData.svc/Products(200) HTTP/1.1</p>
<p>DataServiceVersion: 1.0;NetFx</p>
<p>MaxDataServiceVersion: 3.0;NetFx</p>
<p>Accept: application/json;odata=minimalmetadata</p>
<p>Accept-Charset: UTF-8</p>
<p>User-Agent: Microsoft ADO.NET Data Services</p>
<p>Host: services.odata.org</p>
<p>&nbsp;</p>
<h2>Create an Entry</h2>
<p>&nbsp;</p>
<p>POST http://services.odata.org/v3/(S(ettihtez1pypsghekhjamb1u))/odata/odata.svc/Products HTTP/1.1</p>
<p>DataServiceVersion: 3.0;NetFx</p>
<p>MaxDataServiceVersion: 3.0;NetFx</p>
<p>Content-Type: application/json;odata=minimalmetadata</p>
<p>Accept: application/json;odata=minimalmetadata</p>
<p>Accept-Charset: UTF-8</p>
<p>User-Agent: Microsoft ADO.NET Data Services</p>
<p>Host: services.odata.org</p>
<p>Content-Length: 180</p>
<p>Expect: 100-continue</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Product",<br /> &nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:200,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"My&nbsp;new&nbsp;product&nbsp;from&nbsp;leo",<br /> &nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"5.6",<br /> &nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"0001-01-01T00:00:00"<br /> }</p>
</div>
<p>&nbsp;</p>
<p>Update an Entry with PATCH and PUT</p>
<p><strong>PATCH</strong></p>
<p>Services SHOULD support&nbsp;PATCH&nbsp;as the preferred means of updating an entity.&nbsp;PATCH&nbsp;provides more resiliency between clients and services by directly modifying only those values specified by the client.</p>
<p>PATCH http://services.odata.org/V3/(S(ettihtez1pypsghekhjamb1u))/OData/OData.svc/Products(200) HTTP/1.1</p>
<p>DataServiceVersion: 3.0;NetFx</p>
<p>MaxDataServiceVersion: 3.0;NetFx</p>
<p>Content-Type: application/json;odata=minimalmetadata</p>
<p>Accept: application/json;odata=minimalmetadata</p>
<p>Accept-Charset: UTF-8</p>
<p>User-Agent: Microsoft ADO.NET Data Services</p>
<p>Host: services.odata.org</p>
<p>Content-Length: 180</p>
<p>Expect: 100-continue</p>
<p>&nbsp;</p>
<div>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Update name from leo"<br /> }</p>
</div>
<h2>&nbsp;</h2>
<p><strong>PUT</strong></p>
<p>Services MAY additionally support&nbsp;PUT, but should be aware of the potential for data-loss in round-tripping properties that the client may not know about in advance, such as open or added properties, or properties not specified in metadata. Services that support&nbsp;PUT&nbsp;MUST replace all values of structural properties with those specified in the request body</p>
<p>PUT http://services.odata.org/V3/(S(ettihtez1pypsghekhjamb1u))/OData/OData.svc/Products(200) HTTP/1.1</p>
<p>DataServiceVersion: 3.0;NetFx</p>
<p>MaxDataServiceVersion: 3.0;NetFx</p>
<p>Content-Type: application/json;odata=minimalmetadata</p>
<p>Accept: application/json;odata=minimalmetadata</p>
<p>Accept-Charset: UTF-8</p>
<p>User-Agent: Microsoft ADO.NET Data Services</p>
<p>Host: services.odata.org</p>
<p>Content-Length: 180</p>
<p>Expect: 100-continue</p>
<p>&nbsp;</p>
<div>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Product",<br /> &nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:200,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Update name from leo",<br /> &nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"5.6",<br /> &nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"0001-01-01T00:00:00"<br /> }</p>
</div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Read Complex Type</h2>
<p>&nbsp;</p>
<p><a href="http://services.odata.org/V3/OData/OData.svc/Suppliers(1)/Address?$format=json">http://services.odata.org/V3/OData/OData.svc/Suppliers(1)/Address?$format=json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#ODataDemo.Address">http://services.odata.org/V3/OData/OData.svc/$metadata#ODataDemo.Address</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"Street"</strong>:"NE&nbsp;40th",<br /> &nbsp;&nbsp;&nbsp;<strong>"City"</strong>:"Redmond",<br /> &nbsp;&nbsp;&nbsp;<strong>"State"</strong>:"WA",<br /> &nbsp;&nbsp;&nbsp;<strong>"ZipCode"</strong>:"98052",<br /> &nbsp;&nbsp;&nbsp;<strong>"Country"</strong>:"USA"<br /> }</p>
<p>&nbsp;</p>
<h2>Read Entry with expanded navigation links</h2>
<p><a href="http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Category?$expand=ID&amp;$format=json">http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Category?$expand=ID&amp;$format=json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Categories/@Element">http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Categories/@Element</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Food"<br /> }</p>
<h2>Read Service document</h2>
<p><a href="http://odataservices.azurewebsites.net/OData/OData.svc/?$format=json">http://odataservices.azurewebsites.net/OData/OData.svc/?$format=json</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://odataservices.azurewebsites.net/OData/OData.svc/$metadata">http://odataservices.azurewebsites.net/OData/OData.svc/$metadata</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"value"</strong>:[<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"name"</strong>:"Products",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"url"</strong>:"Products"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"name"</strong>:"Advertisements",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"url"</strong>:"Advertisements"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"name"</strong>:"Categories",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"url"</strong>:"Categories"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"name"</strong>:"Suppliers",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"url"</strong>:"Suppliers"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;]</p>
<h2>&nbsp;</h2>
<h2>Read an EntitySet with full metadata</h2>
<p>http://services.odata.org/V3/OData/OData.svc/Products?$format=application/json;odata=fullmetadata</p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#Products">http://services.odata.org/V3/OData/OData.svc/$metadata#Products</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"value"</strong>:[<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Product",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.id"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/Products(0">http://services.odata.org/V3/OData/OData.svc/Products(0</a>)",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.editLink"</strong>:"Products(0)",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.navigationLinkUrl"><strong>Category@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(0)/Category",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.associationLinkUrl"><strong>Category@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(0)/$links/Category",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.navigationLinkUrl"><strong>Supplier@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(0)/Supplier",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.associationLinkUrl"><strong>Supplier@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(0)/$links/Supplier",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Bread",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Whole&nbsp;grain&nbsp;bread",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:ReleaseDate@odata.type"><strong>ReleaseDate@odata.type</strong></a><strong>"</strong>:"Edm.DateTime",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"1992-01-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:4,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Price@odata.type"><strong>Price@odata.type</strong></a><strong>"</strong>:"Edm.Decimal",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"2.5"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Product",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.id"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/Products(1">http://services.odata.org/V3/OData/OData.svc/Products(1</a>)",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"odata.editLink"</strong>:"Products(1)",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.navigationLinkUrl"><strong>Category@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(1)/Category",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.associationLinkUrl"><strong>Category@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(1)/$links/Category",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.navigationLinkUrl"><strong>Supplier@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(1)/Supplier",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.associationLinkUrl"><strong>Supplier@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(1)/$links/Supplier",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:1,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Milk",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Low&nbsp;fat&nbsp;milk",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:ReleaseDate@odata.type"><strong>ReleaseDate@odata.type</strong></a><strong>"</strong>:"Edm.DateTime",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"1995-10-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:3,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Price@odata.type"><strong>Price@odata.type</strong></a><strong>"</strong>:"Edm.Decimal",<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"3.5"<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;]<br /> }</p>
<h2>&nbsp;</h2>
<h2>Read an Entity with full metadata</h2>
<p>&nbsp;</p>
<p><a href="http://services.odata.org/V3/OData/OData.svc/Products(2)?$format=application/json;odata=fullmetadata">http://services.odata.org/V3/OData/OData.svc/Products(2)?$format=application/json;odata=fullmetadata</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/$metadata#Products/@Element">http://services.odata.org/V3/OData/OData.svc/$metadata#Products/@Element</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Product",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.id"</strong>:"<a href="http://services.odata.org/V3/OData/OData.svc/Products(2">http://services.odata.org/V3/OData/OData.svc/Products(2</a>)",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.editLink"</strong>:"Products(2)",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.navigationLinkUrl"><strong>Category@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(2)/Category",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Category@odata.associationLinkUrl"><strong>Category@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(2)/$links/Category",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.navigationLinkUrl"><strong>Supplier@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Products(2)/Supplier",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Supplier@odata.associationLinkUrl"><strong>Supplier@odata.associationLinkUrl</strong></a><strong>"</strong>:"Products(2)/$links/Supplier",<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:2,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Vint&nbsp;soda",<br /> &nbsp;&nbsp;&nbsp;<strong>"Description"</strong>:"Americana&nbsp;Variety&nbsp;-&nbsp;Mix&nbsp;of&nbsp;6&nbsp;flavors",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:ReleaseDate@odata.type"><strong>ReleaseDate@odata.type</strong></a><strong>"</strong>:"Edm.DateTime",<br /> &nbsp;&nbsp;&nbsp;<strong>"ReleaseDate"</strong>:"2000-10-01T00:00:00",<br /> &nbsp;&nbsp;&nbsp;<strong>"DiscontinuedDate"</strong>:null,<br /> &nbsp;&nbsp;&nbsp;<strong>"Rating"</strong>:3,<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Price@odata.type"><strong>Price@odata.type</strong></a><strong>"</strong>:"Edm.Decimal",<br /> &nbsp;&nbsp;&nbsp;<strong>"Price"</strong>:"20.9"<br /> }</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Read Entry with expanded navigation links with full metadata</h2>
<p>&nbsp;</p>
<p><a href="http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Category?$expand=ID&amp;$format=application/json;odata=fullmetadata">http://odataservices.azurewebsites.net/OData/OData.svc/Products(0)/Category?$expand=ID&amp;$format=application/json;odata=fullmetadata</a></p>
<p>{<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.metadata"</strong>:"<a href="http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Categories/@Element">http://odataservices.azurewebsites.net/OData/OData.svc/$metadata#Categories/@Element</a>",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.type"</strong>:"ODataDemo.Category",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.id"</strong>:"<a href="http://odataservices.azurewebsites.net/OData/OData.svc/Categories(0">http://odataservices.azurewebsites.net/OData/OData.svc/Categories(0</a>)",<br /> &nbsp;&nbsp;&nbsp;<strong>"odata.editLink"</strong>:"Categories(0)",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Products@odata.navigationLinkUrl"><strong>Products@odata.navigationLinkUrl</strong></a><strong>"</strong>:"Categories(0)/Products",<br /> &nbsp;&nbsp;&nbsp;<strong>"</strong><a href="mailto:Products@odata.associationLinkUrl"><strong>Products@odata.associationLinkUrl</strong></a><strong>"</strong>:"Categories(0)/$links/Products",<br /> &nbsp;&nbsp;&nbsp;<strong>"ID"</strong>:0,<br /> &nbsp;&nbsp;&nbsp;<strong>"Name"</strong>:"Food"<br /> }</p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>