{"id":1523,"date":"2009-12-17T09:48:00","date_gmt":"2009-12-17T09:48:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2009\/12\/17\/getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1\/"},"modified":"2018-09-04T18:01:49","modified_gmt":"2018-09-04T18:01:49","slug":"getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1\/","title":{"rendered":"Getting Started with the Data Services Update for .NET 3.5 SP1 \u2013 Part 1"},"content":{"rendered":"<p>Yesterday we released the <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2010\/01\/27\/data-services-update-for-net-3-5-sp1-available-for-download.aspx\">Data Services Update for .NET 3.5 SP1<\/a> that basically brings the functionality available in .NET 4.0 to .NET 3.5 too.<\/p>\n<p>To help you get started with the Update, in this post we will:<\/p>\n<ul>\n<li>Install the Update <\/li>\n<li>Create a database. <\/li>\n<li>Create a Web Application containing: \n<ul>\n<li>An Entity Data Model (EDM) to expose the database <\/li>\n<li>A configured Data Service to expose the EDM using V2 of the <a href=\"https:\/\/odata.org\">OData protocol<\/a>&nbsp; <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>And in Part 2 we will Create a WPF Application to use the Data Service <\/p>\n<p>So without further ado, lets get started\u2026<\/p>\n<h3>Walkthrough:<\/h3>\n<h4>Step 1 \u2013 Install the Update:<\/h4>\n<p>There are two installs one <a href=\"https:\/\/www.microsoft.com\/downloads\/details.aspx?familyid=79d7f6f8-d6e9-4b8c-8640-17f89452148e&amp;displaylang=en\">for Windows7 or Windows Server 2008 R2<\/a> and one <a href=\"https:\/\/www.microsoft.com\/downloads\/details.aspx?familyid=4B710B89-8576-46CF-A4BF-331A9306D555&amp;displaylang=en\">for all other supported versions of Windows<\/a> simply download and install the right one for your machine.<\/p>\n<h4>Step 2 \u2013 Create the Database:<\/h4>\n<p>Next create the database (we are using .NET 3.5 here so unfortunately we don\u2019t yet have <a href=\"http:\/\/blogs.msdn.com\/adonet\/archive\/2009\/05\/12\/sneak-preview-model-first-in-the-entity-framework-4-0.aspx\">Model First<\/a>), so go into your database management tool off choice, say SQL Server Management Studio, and run <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/attachment\/9938290.ashx\">this script<\/a>.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/NewDatabase.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/NewDatabase_thumb.png\" style=\"border-width: 0px\" title=\"NewDatabase\" alt=\"NewDatabase\" width=\"244\" border=\"0\" height=\"180\"><\/a> <\/p>\n<p>After you\u2019ve done that you should have a <i>GettingStartedWithUpdate<\/i> database.<\/p>\n<p>The database will have two tables Products and Categories, and one relationship.<\/p>\n<p>The <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/attachment\/9938290.ashx\">script<\/a> also include some sample data so that your database should have 2 Categories and 2 Products.<\/p>\n<h4>Step 3 \u2013 Create a Web Application:<\/h4>\n<p>Next start up Visual Studio 2008 and create a new Web Application like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/NewWebsite.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/NewWebsite_thumb.png\" style=\"border-width: 0px\" title=\"NewWebsite\" alt=\"NewWebsite\" width=\"244\" border=\"0\" height=\"167\"><\/a>&nbsp;<\/p>\n<h4>Step 4 \u2013 Create an Entity Data Model:<\/h4>\n<p>Right Click on your project in Solution Explorer and select \u2018Add New Item\u2019, choose \u2018ADO.NET Entity Data Model\u2019 and give your model a name:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/NewModel.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/NewModel_thumb.png\" style=\"border-width: 0px\" title=\"NewModel\" alt=\"NewModel\" width=\"244\" border=\"0\" height=\"149\"><\/a> <\/p>\n<p>You will be asked to choose between \u2018Generate from a database\u2019 or \u2018Empty model\u2019:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/GenerateFromModel.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/GenerateFromModel_thumb.png\" style=\"border-width: 0px\" title=\"GenerateFromModel\" alt=\"GenerateFromModel\" width=\"244\" border=\"0\" height=\"222\"><\/a> <\/p>\n<p>Choose \u2018Generate from a database\u2019, next you will be prompted for a database connection:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/CreateConnection.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/CreateConnection_thumb.png\" style=\"border-width: 0px\" title=\"CreateConnection\" alt=\"CreateConnection\" width=\"244\" border=\"0\" height=\"222\"><\/a> <\/p>\n<p>Because we don\u2019t have a connection to \u2018GettingStartedWithUpdate\u2019 yet we need to create one by clicking \u2018New Connection\u2026\u2019:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ChooseDataSource.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ChooseDataSource_thumb.png\" style=\"border-width: 0px\" title=\"ChooseDataSource\" alt=\"ChooseDataSource\" width=\"244\" border=\"0\" height=\"140\"><\/a>&nbsp;<\/p>\n<p>On the \u2018Choose Data Source\u2019 screen select \u2018Microsoft SQL Server\u2019 and hit Continue:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ConnectionProperties.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ConnectionProperties_thumb.png\" style=\"border-width: 0px\" title=\"ConnectionProperties\" alt=\"ConnectionProperties\" width=\"166\" border=\"0\" height=\"244\"><\/a> <\/p>\n<p>Fill in the Server and Database details, then click \u2018OK\u2019 to return to the \u2018Choose Your Data Connection\u2019 screen and then click \u2018Next\u2019:<\/p>\n<p>Next you are asked what database objects you want in your model, select both tables:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ChooseDatabaseObjects.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ChooseDatabaseObjects_thumb.png\" style=\"border-width: 0px\" title=\"ChooseDatabaseObjects\" alt=\"ChooseDatabaseObjects\" width=\"244\" border=\"0\" height=\"222\"><\/a> <\/p>\n<p>Select Finish, and finally you should see something like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/Model_1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/Model_thumb_1.png\" style=\"border-width: 0px\" title=\"Model\" alt=\"Model\" width=\"244\" border=\"0\" height=\"135\"><\/a> <\/p>\n<p>Then do a little model fix-up by\u2026<\/p>\n<ul>\n<li>Renaming <i>Categories<\/i> to <i>Category<\/i> <\/li>\n<li>Renaming <i>Products<\/i> to <i>Product<\/i> <\/li>\n<li>Renaming Product.<i>Categories<\/i> to Product.<i>Category<\/i> <\/li>\n<\/ul>\n<p>So that your model looks like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ModelFixedUp.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ModelFixedUp_thumb.png\" style=\"border-width: 0px\" title=\"ModelFixedUp\" alt=\"ModelFixedUp\" width=\"244\" border=\"0\" height=\"113\"><\/a> <\/p>\n<p><font color=\"#404040\"><b>NOTE:<\/b> in .NET 4.0 this step is no longer required because <\/font><a href=\"http:\/\/blogs.msdn.com\/adonet\/archive\/2009\/05\/20\/sneak-preview-pluralization-in-entity-framework-4-0.aspx\"><font color=\"#404040\">EF Pluralization<\/font><\/a><font color=\"#404040\"> does this for you automatically.<\/font><\/p>\n<p>Now we are ready to expose our Model as a Data Service\u2026<\/p>\n<h4>Step 5 \u2013 Create a Data Service to expose our Model:<\/h4>\n<p>Right click on your project and select \u2018Add new Item\u2019:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AddProductsService.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/AddProductsService_thumb.png\" style=\"border-width: 0px\" title=\"AddProductsService\" alt=\"AddProductsService\" width=\"244\" border=\"0\" height=\"149\"><\/a> <\/p>\n<p>Select \u2018ADO.NET Data Service\u2019 and call it \u2018ProductsService.svc\u2019.<\/p>\n<p>You should end up with something that looks like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/PostAddDataService.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/PostAddDataService_thumb.png\" style=\"border-width: 0px\" title=\"PostAddDataService\" alt=\"PostAddDataService\" width=\"244\" border=\"0\" height=\"183\"><\/a> <\/p>\n<p>Next configure the ProductsService to expose our EDM like this: <\/p>\n<p><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; <\/font><font face=\"Courier New\">public class ProductsService : DataService&lt;GettingStartedWithUpdateEntities&gt; <br>&nbsp;&nbsp;&nbsp; {<\/font><\/p>\n<p>The GettingStartedWithUpdateEntities here is simply the name of the strongly typed ObjectContext class generated by the Entity Framework to interact with our model.<\/p>\n<h4>Step 6 \u2013 Configure the Data Service to use V2:<\/h4>\n<p>Next to take advantage of the all the new features in the Update you need to change this:<\/p>\n<p><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; public static void InitializeService(IDataServiceConfiguration config) <br>&nbsp;&nbsp;&nbsp; {<\/font> <br><\/p>\n<p>To this:<\/p>\n<p><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; public static void InitializeService(DataServiceConfiguration config) <br>&nbsp;&nbsp;&nbsp; {<\/font> <\/p>\n<p>The DataServiceConfiguration class has a DataServiceBehavior property which is not available via IDataServiceConfiguration interface.<\/p>\n<p>Using the DataServiceBehavior property we can tell Data Services to support V2 of the protocol:<\/p>\n<p><font face=\"Courier New\"><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; <\/font>config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; <br><\/font><\/p>\n<h4>Step 7 \u2013 Expose ResourceSets:<\/h4>\n<p>Finally we configure the Data Service to expose only the parts of the model we want exposed. Our EDM has a ProductSet and a CategorySet, but clients of this Data Service need read-only access to the CategorySet, for lookups etc, and read-write access to the ProductSet, so they can add and modify products: <\/p>\n<p><font face=\"Courier New\"><font face=\"Courier New\"><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; <\/font><\/font>config.SetEntitySetAccessRule(&#8220;CategorySet&#8221;, EntitySetRights.AllRead); <br><font face=\"Courier New\"><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; <\/font><\/font>config.SetEntitySetAccessRule(&#8220;ProductSet&#8221;, EntitySetRights.All);<\/font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/p>\n<p>After all our changes our Data Service should look like this:<\/p>\n<p><font face=\"Courier New\">public class ProductsService : DataService&lt;GettingStartedWithUpdateEntities&gt; <br>{ <br>&nbsp;&nbsp;&nbsp; \/\/ This method is called only once to initialize service-wide policies. <br>&nbsp;&nbsp;&nbsp; public static void InitializeService(DataServiceConfiguration config) <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.SetEntitySetAccessRule(&#8220;CategorySet&#8221;, EntitySetRights.AllRead); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.SetEntitySetAccessRule(&#8220;ProductSet&#8221;, EntitySetRights.All); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;&nbsp; <br>&nbsp;&nbsp;&nbsp; } <br>}<\/font><\/p>\n<h3>Step 8 \u2013 Verify our Service is up and running:<\/h3>\n<p>The next step is pretty simple, set ProductsService.svc as the startup page of your Web Application and debug your website. <\/p>\n<p>You should see something like this in your Browser:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ResourceDocument.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ResourceDocument_thumb.png\" style=\"border-width: 0px\" title=\"ResourceDocument\" alt=\"ResourceDocument\" width=\"244\" border=\"0\" height=\"184\"><\/a> <\/p>\n<p>You can then browse to one of the sets, and by default you will see internet explorer\u2019s feed view, which proves your Data Service is working:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ProductSet.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/ProductSet_thumb.png\" style=\"border-width: 0px\" title=\"ProductSet\" alt=\"ProductSet\" width=\"244\" border=\"0\" height=\"184\"><\/a> <\/p>\n<p>If you want to see the raw XML \/ ATOM simply turn off the feeds view (by selecting \u2018Internet Options\u2019  Content tab  Feeds Setting  Uncheck \u2018Turn on feed reading view\u2019).<\/p>\n<p>Then you can try an Update specific feature like projections, by using the <b>$select <\/b>operator like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AtomFeed$select.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2009\/12\/AtomFeedselect_thumb.png\" style=\"border-width: 0px\" title=\"AtomFeed$select\" alt=\"AtomFeed$select\" width=\"244\" border=\"0\" height=\"184\"><\/a> <\/p>\n<p>At this point your service is up and running.<\/p>\n<p>If you want to play around more with your Data Service here is a <a href=\"http:\/\/blogs.msdn.com\/alexj\/archive\/2009\/11\/18\/tip-44-how-to-navigate-an-odata-compliant-service.aspx\">handy quick guide to navigating your Data Service<\/a>. <\/p>\n<h3>Summary:<\/h3>\n<p>In this post we learned how to get started with the Data Services Update for .NET 3.5 SP1. <\/p>\n<p>We walked through creating a Database, an Entity Data Model over that Database and a Data Service to expose that model.<\/p>\n<p>We saw how to configure our Data Service to use V2 of the OData protocol and newer features like Projections and inline count.<\/p>\n<p>In the next post we will build a simple WPF application to work against our shiny new Data Service.<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/alexj\"><b>Alex James<\/b><\/a><b> <br><b>Program Manager, Data Frameworks Team.<\/b><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday we released the Data Services Update for .NET 3.5 SP1 that basically brings the functionality available in .NET 4.0 to .NET 3.5 too. To help you get started with the Update, in this post we will: Install the Update Create a database. Create a Web Application containing: An Entity Data Model (EDM) to expose [&hellip;]<\/p>\n","protected":false},"author":512,"featured_media":3253,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[6,37,48,74],"class_list":["post-1523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-ado-net-data-services","tag-how-to","tag-odata","tag-tutorial"],"acf":[],"blog_post_summary":"<p>Yesterday we released the Data Services Update for .NET 3.5 SP1 that basically brings the functionality available in .NET 4.0 to .NET 3.5 too. To help you get started with the Update, in this post we will: Install the Update Create a database. Create a Web Application containing: An Entity Data Model (EDM) to expose [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1523","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\/512"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/comments?post=1523"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media\/3253"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}