{"id":324,"date":"2020-11-21T10:52:52","date_gmt":"2020-11-21T10:52:52","guid":{"rendered":"https:\/\/turtleflyblog.com\/?p=324"},"modified":"2022-02-28T09:26:00","modified_gmt":"2022-02-28T09:26:00","slug":"odata-protocol","status":"publish","type":"post","link":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/","title":{"rendered":"OData Protocol"},"content":{"rendered":"\n

OData Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using OData.<\/p>\n\n\n\n

OData Expression Language<\/strong><\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

OData Query Language<\/strong><\/p>\n\n\n\n

Odata Query Options<\/strong><\/a><\/td>Meaning<\/strong><\/td><\/tr>
$top = n<\/strong><\/td>Return the first nth data<\/strong><\/td><\/tr>
$skip = n<\/strong><\/td>Skip the first nth data<\/strong><\/td><\/tr>
$Orderby<\/strong><\/td>Return the data in ascending or descending or<\/strong><\/td><\/tr>
$filter<\/strong><\/td>Return the data which satisfies the filter condition<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

ASP.NET FRAMEWORK<\/strong><\/p>\n\n\n\n

Download OData package<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Now, we have to append WebApiConfig.cs<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Controller must inherit ODataController class<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Then for Web Api, add [EnableQuery] Attribute for the HTTP method<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

ASP.NET CORE<\/strong><\/p>\n\n\n\n

Same to ASP.NET FRAMEWORK, we have to download OData package firstly<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Then add codes shown below<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Lastly, remember to add [EnableQuery] Attribute prior to the HTTP method<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

OData Example<\/strong><\/p>\n\n\n\n

The following example will use Product class below<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Then set the data for testing<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

After the execution of Visual Studio or any other IDE, enter the URL<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

You then will see the result json like this.<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

On the other hand, if you want to see both fields (Name and Price), you need to fix the URL<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

The result will look like<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n

Say you then have a new request, you want to see the price of the product list in the order from low to high, you just need to add $OrderBy semantics to the URL<\/p>\n\n\n\n

\"\"<\/figure>\n\n\n\n
\"\"<\/figure>\n\n\n\n

Conclusion<\/strong><\/p>\n\n\n\n

The above example manifests the potential of OData. We just have to append query language to get the data structure we want. However for the other Restful API method, we may have to add and fix large segments of the original code written to achieve our goal. For the OData, we only need to add or change small part of code to allow OData work on either ASP.NET FRAMEWORK or ASP.NET CORE framework. Hence, OData is an useful and flexible standard to achieve Restful architecture.<\/p>\n","protected":false},"excerpt":{"rendered":"

OData Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-324","post","type-post","status-publish","format-standard","hentry","category-programming-2"],"yoast_head":"\nOData Protocol - Who said turtle cannot fly<\/title>\n<meta name=\"description\" content=\"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OData Protocol - Who said turtle cannot fly\" \/>\n<meta property=\"og:description\" content=\"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O\" \/>\n<meta property=\"og:url\" content=\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/\" \/>\n<meta property=\"og:site_name\" content=\"Who said turtle cannot fly\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-21T10:52:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-28T09:26:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png\" \/>\n<meta name=\"author\" content=\"Joseph\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Joseph\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/\",\"url\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/\",\"name\":\"OData Protocol - Who said turtle cannot fly\",\"isPartOf\":{\"@id\":\"https:\/\/turtleflyblog.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png\",\"datePublished\":\"2020-11-21T10:52:52+00:00\",\"dateModified\":\"2022-02-28T09:26:00+00:00\",\"author\":{\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\"},\"description\":\"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O\",\"breadcrumb\":{\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#breadcrumb\"},\"inLanguage\":\"en-AU\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png?fit=529%2C405&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png?fit=529%2C405&ssl=1\",\"width\":529,\"height\":405},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/turtleflyblog.com\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OData Protocol\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/turtleflyblog.com\/#website\",\"url\":\"https:\/\/turtleflyblog.com\/\",\"name\":\"Who said turtle cannot fly\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/turtleflyblog.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-AU\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172\",\"name\":\"Joseph\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-AU\",\"@id\":\"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g\",\"caption\":\"Joseph\"},\"sameAs\":[\"https:\/\/turtleflyblog.com\/\/\"],\"url\":\"https:\/\/turtleflyblog.com\/author\/joseph\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OData Protocol - Who said turtle cannot fly","description":"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/","og_locale":"en_US","og_type":"article","og_title":"OData Protocol - Who said turtle cannot fly","og_description":"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O","og_url":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/","og_site_name":"Who said turtle cannot fly","article_published_time":"2020-11-21T10:52:52+00:00","article_modified_time":"2022-02-28T09:26:00+00:00","og_image":[{"url":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png"}],"author":"Joseph","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Joseph","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/","url":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/","name":"OData Protocol - Who said turtle cannot fly","isPartOf":{"@id":"https:\/\/turtleflyblog.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage"},"image":{"@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage"},"thumbnailUrl":"https:\/\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png","datePublished":"2020-11-21T10:52:52+00:00","dateModified":"2022-02-28T09:26:00+00:00","author":{"@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172"},"description":"Protocol (Open Data Protocol) was released by Microsoft in 2007. The current version has been upgraded to 4.0. Now OASIS (Organization for the Advancement of Structured Information Standards) has approved this protocol standard. OData is based on REST principle to offer HTTP CRUD service. This protocol also provides special query language expression to help clients filter the query result and customize the data model. This enables the users don\u2019t have to largely change their code to get the data structure and format they want. Now both ASP.NET CORE and ASP.NET FRAMEWORK support OData. This article will reveal how to make OData work on these two frameworks and shows the real examples of using O","breadcrumb":{"@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#breadcrumb"},"inLanguage":"en-AU","potentialAction":[{"@type":"ReadAction","target":["https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/"]}]},{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#primaryimage","url":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png?fit=529%2C405&ssl=1","contentUrl":"https:\/\/i0.wp.com\/turtleflyblog.com\/wp-content\/uploads\/2020\/11\/image-5.png?fit=529%2C405&ssl=1","width":529,"height":405},{"@type":"BreadcrumbList","@id":"https:\/\/turtleflyblog.com\/en\/2020\/11\/21\/odata-protocol\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/turtleflyblog.com\/en\/"},{"@type":"ListItem","position":2,"name":"OData Protocol"}]},{"@type":"WebSite","@id":"https:\/\/turtleflyblog.com\/#website","url":"https:\/\/turtleflyblog.com\/","name":"Who said turtle cannot fly","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/turtleflyblog.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-AU"},{"@type":"Person","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/130c2e1bdce4a8ba27bfe14c65988172","name":"Joseph","image":{"@type":"ImageObject","inLanguage":"en-AU","@id":"https:\/\/turtleflyblog.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/539caa7bc4af75cd4ab82fc8d51935da?s=96&d=mm&r=g","caption":"Joseph"},"sameAs":["https:\/\/turtleflyblog.com\/\/"],"url":"https:\/\/turtleflyblog.com\/author\/joseph\/"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/comments?post=324"}],"version-history":[{"count":1,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/324\/revisions"}],"predecessor-version":[{"id":664,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/posts\/324\/revisions\/664"}],"wp:attachment":[{"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/media?parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/categories?post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/turtleflyblog.com\/wp-json\/wp\/v2\/tags?post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}