{"id":3954,"date":"2020-04-06T17:18:31","date_gmt":"2020-04-07T00:18:31","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/odata\/?p=3954"},"modified":"2020-04-06T17:18:31","modified_gmt":"2020-04-07T00:18:31","slug":"move-odata-to-net-5","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/move-odata-to-net-5\/","title":{"rendered":"Move OData to .NET 5"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Along with the <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-5-0-preview-1\/\">Announcing .NET 5 preview 1<\/a>, it\u2019s time to move OData to .NET 5.\u00a0This blog is intended to describe how easy to move the <strong>BookStore<\/strong> sample introduced in <a href=\"https:\/\/devblogs.microsoft.com\/odata\/asp-net-core-odata-now-available\/\">ASP.NET Core OData now Available\u00a0<\/a> onto .NET 5.<\/p>\n<p>Let&#8217;s get started.<\/p>\n<h2>Install .NET 5<\/h2>\n<p>.NET 5 SDK is required to build the .NET 5 application. So, Let\u2019s follow up the instructions in <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-5-0-preview-1\/\">Announcing .NET 5 preview 1<\/a> to install the .NET 5 SDK.<\/p>\n<p>Meanwhile, I also install the Visual Studio 2019 Preview to edit and compile the .NET 5 project. It&#8217;s easy to download Visual Studio 2019 Preview from <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/\">here<\/a>. The required VS version supporting .NET 5 is 16.6.<\/p>\n<h2>Updating BookStore Project<\/h2>\n<p>It\u2019s easy to target the <strong>BookStore<\/strong> project to .NET 5 when we finish the installation of .NET 5.<\/p>\n<p>Just open the <strong>BookStore<\/strong> solution, double click the project, then edit the &#8220;<em>BookStore.csproj<\/em>&#8221; contents as below:<\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/gist.github.com\/xuzhg\/309825fe6f1b57c3331d5b230d29281e.js\"><\/script><\/p>\n<h2>Updating the codes<\/h2>\n<p>&nbsp;<\/p>\n<p>In order to compile the project, we have to change some codes in the <em>Startup.cs<\/em>.<\/p>\n<p>First, in <strong>ConfigureServices()<\/strong> method, change its content as below:<\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/gist.github.com\/xuzhg\/2e9abc4043ab816ae919bc68a483c777.js\"><\/script><\/p>\n<p>Then, in <strong>Configure()<\/strong> method, change its content as below:<\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/gist.github.com\/xuzhg\/abe487a81d209655d8247471a29fdce3.js\"><\/script><\/p>\n<p><strong>Be noted<\/strong>, the parameter <strong>\u2018IHostingEnvironment\u2019<\/strong> of <strong>Configure()<\/strong> should change to use \u201c<strong>IWebHostEnvironment\u2019<\/strong>.<\/p>\n<p>&nbsp;<\/p>\n<h2>Query the Resources<\/h2>\n<p>That\u2019s all. Now, we can build and run the book store application.<\/p>\n<p>For example:<\/p>\n<p>We can file a GET request as : <strong><a href=\"http:\/\/localhost:5001\/odata\/Books(2)\">http:\/\/localhost:5001\/odata\/Books(2)<\/a><\/strong><\/p>\n<p>And the response returns the second book as follows:<\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/gist.github.com\/xuzhg\/0e6bece039c2c778b954a137ec110371.js\"><\/script><\/p>\n<p>The application also supports the advanced OData query options like:<\/p>\n<p><strong>http:\/\/localhost:5001\/odata\/Books?$filter=Price le 50&amp;$expand=Press($select=Name)&amp;$select=ISBN,Location($select=Street)<\/strong><\/p>\n<p>The response payload should look like:<\/p>\n<p><script type=\"text\/javascript\" src=\"https:\/\/gist.github.com\/xuzhg\/67ff68102098bf972260e6ac0decda56.js\"><\/script><\/p>\n<h2>Summary<\/h2>\n<p>Thanks for reading. We encourage you to download the latest\u00a0ASP.NET Core OData package from\u00a0<a href=\"https:\/\/www.nuget.org\/packages\/Microsoft.AspNetCore.OData\">Nuget.org<\/a> and start building amazing OData service running on any .NET 5 platforms, such as Windows, MacOS and Linux.\u00a0 Enjoy it!<\/p>\n<p>You can refer to <a href=\"https:\/\/github.com\/xuzhg\/MyAspNetCore\/tree\/master\/src\/BookStoreDotNet5\">here<\/a> for the sample project created in this blog. Any questions or concerns, feel free email to <a href=\"mailto:saxu@microsoft.com\">saxu@microsoft.com<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Along with the Announcing .NET 5 preview 1, it\u2019s time to move OData to .NET 5.\u00a0This blog is intended to describe how easy to move the BookStore sample introduced in ASP.NET Core OData now Available\u00a0 onto .NET 5. Let&#8217;s get started. Install .NET 5 .NET 5 SDK is required to build the .NET 5 [&hellip;]<\/p>\n","protected":false},"author":514,"featured_media":3549,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1,117],"tags":[1177,48],"class_list":["post-3954","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","category-webapi","tag-net-5","tag-odata"],"acf":[],"blog_post_summary":"<p>Introduction Along with the Announcing .NET 5 preview 1, it\u2019s time to move OData to .NET 5.\u00a0This blog is intended to describe how easy to move the BookStore sample introduced in ASP.NET Core OData now Available\u00a0 onto .NET 5. Let&#8217;s get started. Install .NET 5 .NET 5 SDK is required to build the .NET 5 [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/3954","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/users\/514"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=3954"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/3954\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3549"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=3954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=3954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=3954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}