{"id":1483,"date":"2010-01-28T10:51:00","date_gmt":"2010-01-28T10:51:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/odatateam\/2010\/01\/28\/getting-started-with-the-data-service-update-for-net-3-5-sp1-part-2\/"},"modified":"2018-09-04T18:01:37","modified_gmt":"2018-09-04T18:01:37","slug":"getting-started-with-the-data-service-update-for-net-3-5-sp1-part-2","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/odata\/getting-started-with-the-data-service-update-for-net-3-5-sp1-part-2\/","title":{"rendered":"Getting Started with the Data Service Update for .NET 3.5 SP1 \u2013 Part 2"},"content":{"rendered":"<p>In <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2009\/12\/17\/getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1.aspx\">Part 1<\/a> we created a Data Service that exposes V2 of the OData Protocol, in this post we will create a WPF application to consume our Data Service.<\/p>\n<h3>Walkthrough:<\/h3>\n<h4>Step 1 \u2013 Update Code Generation Settings:<\/h4>\n<p>The Data Services Update is basically a patch to .NET 3.5 SP1, so it can\u2019t break existing projects, this means we need a way to opt-in to the new Code-Gen features.<\/p>\n<p>To do this after you installed the update you need to create two environment variables:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/EnvironmentVariables.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/EnvironmentVariables_thumb.png\" style=\"border-width: 0px\" title=\"EnvironmentVariables\" alt=\"EnvironmentVariables\" width=\"244\" border=\"0\" height=\"184\"><\/a> <\/p>\n<p>Set <b>dscodegen_version<\/b> to <b>2.0<\/b>. This tells CodeGeneration to generate classes that can leverage V2 protocol features.<\/p>\n<p>Set <b>dscodegen_usedsc<\/b> to <b>1<\/b>. This tells CodeGeneration to use DataServiceCollection&lt;&gt; classes wherever possible to track changes and notify both UI code and the DataServiceContext of those changes. <\/p>\n<p><font color=\"#808080\"><b>NOTE:<\/b> VS 2010 has these code generation options too, but in the the RTM version of VS 2010 you will be able to specify options via the Service Reference itself.<\/font><\/p>\n<h4>Step 2 \u2013 Create a WPF client application:<\/h4>\n<p>Next add a WPF Application to the solution you created in <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2009\/12\/17\/getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1.aspx\">Part 1<\/a>:<\/p>\n<p>&nbsp;<a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/CreateWPFClientApp.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/CreateWPFClientApp_thumb.png\" style=\"border-width: 0px\" title=\"CreateWPFClientApp\" alt=\"CreateWPFClientApp\" width=\"244\" border=\"0\" height=\"159\"><\/a> <\/p>\n<h4>Step 3 \u2013 Add a Service Reference:<\/h4>\n<p>Right click on your WPF project reference and click \u201cAdd Service Reference\u201d:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AddServiceRef.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/AddServiceRef_thumb.png\" style=\"border-width: 0px\" title=\"AddServiceRef\" alt=\"AddServiceRef\" width=\"122\" border=\"0\" height=\"244\"><\/a> <\/p>\n<p>One the next screen if the your Data Service is in the same solution click \u2018Discover\u2019, which should populate the address field for you, if not simply enter the Address of your target Data Service by hand:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/AddServiceRefStage2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/AddServiceRefStage2_thumb.png\" style=\"border-width: 0px\" title=\"AddServiceRefStage2\" alt=\"AddServiceRefStage2\" width=\"244\" border=\"0\" height=\"199\"><\/a> <\/p>\n<p>Finally enter a namespace for the generated code and click OK.<\/p>\n<h4>Step 4 \u2013 Verify V2 Code-Gen:<\/h4>\n<p>To make sure Step 1 worked correctly click the \u201cShow All Files\u201d button with your WPF Application selected.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ShowAllFiles.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/ShowAllFiles_thumb.png\" style=\"border-width: 0px\" title=\"ShowAllFiles\" alt=\"ShowAllFiles\" width=\"212\" border=\"0\" height=\"135\"><\/a> <\/p>\n<p>Now under the service reference you added you should be see the Reference.cs file:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/CodeGenOutput.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/CodeGenOutput_thumb.png\" style=\"border-width: 0px\" title=\"CodeGenOutput\" alt=\"CodeGenOutput\" width=\"244\" border=\"0\" height=\"78\"><\/a> <\/p>\n<p>This is where Code-Gen emits your client classes and strongly typed DataServiceContext to allow you to program against your Data Service. <\/p>\n<p>The easiest way to check that everything is using the latest and greatest features is to look for the Products property of the Category class. If everything is working you should see something like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/DataServiceCollection.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/DataServiceCollection_thumb.png\" style=\"border-width: 0px\" title=\"DataServiceCollection\" alt=\"DataServiceCollection\" width=\"244\" border=\"0\" height=\"62\"><\/a> <\/p>\n<p>Notice the return type of this property is DataServiceCollection&lt;Product&gt;which is what we want. <\/p>\n<p>This is because the <b>dscodegen_usedsc<\/b> environment variable tells <b>D<\/b>ata <b>S<\/b>ervices <b>codegen<\/b> to <b>use<\/b> <b>D<\/b>ata<b>S<\/b>ervice<b>C<\/b>ollection instead of standard Collections classes.<\/p>\n<h4>Step 5 \u2013 Add a ViewModel:<\/h4>\n<p>Next add a View Model class for simplifying the interaction between our form and the DataService.<\/p>\n<p>Our Application is going to allow people to view a list of Products, select one and edit it.<\/p>\n<p>So our ViewModel should encapsulate a DataServiceContext to interact with the DataService, an updatable list of Products, and a list of Category reference data, so we can change the Category associated with a Product.<\/p>\n<p>So this is what our ViewModel class looks like:<\/p>\n<p><font face=\"Courier New\">public class ViewModel <br>{ <br>&nbsp;&nbsp;&nbsp; private GettingStartedWithUpdateEntities _ctx; <br>&nbsp;&nbsp;&nbsp; private Category[] _categories; <br>&nbsp;&nbsp;&nbsp; private DataServiceCollection&lt;Product&gt; _products; <\/p>\n<p>&nbsp;&nbsp;&nbsp; public ViewModel() <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ctx = new GettingStartedWithUpdateEntities( <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new Uri(&#8220;http:\/\/localhost:54137\/ProductsService.svc&#8221;)); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Load(); <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; public DataServiceCollection&lt;Product&gt; Products { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get{ <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _products; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; public Category[] Categories <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return _categories; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; public void SaveChanges() <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _ctx.SaveChanges(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Load(); <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; public void Load() <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _categories = _ctx.CategorySet.ToArray(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _products = new DataServiceCollection&lt;Product&gt;(_ctx); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _products.Load(from p in _ctx.ProductSet.Expand(&#8220;Category&#8221;) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select p); <br>&nbsp;&nbsp;&nbsp; } <br>}<\/font><\/p>\n<p>As you can see we have a member variable for holding our strongly typed DataServiceContext (called GettingStartedWithUpdateEntities), and our two lists.<\/p>\n<p><font color=\"#808080\"><b>TIP:<\/b> If you are debugging and you want to know what port you need in your URI, hover over the Visual Studio Web Server icon in your system tray:<\/font><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ServiceRoot.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/ServiceRoot_thumb.png\" style=\"border-width: 0px\" title=\"ServiceRoot\" alt=\"ServiceRoot\" width=\"222\" border=\"0\" height=\"47\"><\/a><\/p>\n<p>The most interesting piece of this code is the DataServiceCollection&lt;Product&gt;, which is new to the Update, and listens for changes and notifies the DataContext of any changes on your behalf:<\/p>\n<p><font face=\"Courier New\">&nbsp;&nbsp;&nbsp; _products = new DataServiceCollection&lt;Product&gt;(_ctx); <br>&nbsp;&nbsp;&nbsp; _products.Load(from p in _ctx.ProductSet.Expand(&#8220;Category&#8221;) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select p);<\/font> <\/p>\n<p>Here that we create a DataServiceCollection bound to the DataService, and then we load it with a query that retrieves all Products. Note that when we query the Products we also pull back the related Category so we can display the products category in the UI.<\/p>\n<p>The SaveChanges() method is simply there as a way of flushing our changes back to the database. <\/p>\n<h4>Step 6 \u2013 Add some WPF Code:<\/h4>\n<p>Now open up the Window.xaml and paste in this code:<\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">&lt;Window x:Class=&#8221;MyClientApp.Window1&#8243; <br>&nbsp;&nbsp;&nbsp; xmlns=&#8221;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml\/presentation&#8221; <br>&nbsp;&nbsp;&nbsp; xmlns:x=&#8221;http:\/\/schemas.microsoft.com\/winfx\/2006\/xaml&#8221; <br>&nbsp;&nbsp;&nbsp; Title=&#8221;Products Catalog&#8221; Height=&#8221;400&#8243; Width=&#8221;425&#8243;&gt; <br>&nbsp;&nbsp;&nbsp; &lt;Grid&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel Orientation=&#8221;Horizontal&#8221;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Grid Margin=&#8221;0,0,0,0&#8243; Name=&#8221;grid1&#8243; Width=&#8221;140&#8243; &gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ListBox ItemsSource=&#8221;{Binding Path=Products}&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name=&#8221;Products&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IsSynchronizedWithCurrentItem=&#8221;True&#8221;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;ListBox.ItemTemplate&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;DataTemplate&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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ackPanel Orientation=&#8221;Vertical&#8221; Width=&#8221;260&#8243;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel Orientation=&#8221;Horizontal&#8221;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Label Name=&#8221;lblName&#8221; Width=&#8221;100&#8243;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBlock Width=&#8221;150&#8243;&gt;Name:&lt;\/TextBlock&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Label&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBox Name=&#8221;txtName&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text=&#8221;{Binding ElementName=Products, Path=SelectedItem.Name, Mode=TwoWay}&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Width=&#8221;150&#8243;\/&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/StackPanel&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel Orientation=&#8221;Horizontal&#8221;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Label Name=&#8221;lblCost&#8221; Width=&#8221;100&#8243;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBlock Width=&#8221;150&#8243; &gt;Cost:&lt;\/TextBlock&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Label&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBox Name=&#8221;txtCost&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Text=&#8221;{Binding ElementName=Products, Path=SelectedItem.Cost, Mode=TwoWay}&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Width=&#8221;150&#8243;\/&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/StackPanel&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;StackPanel Orientation=&#8221;Horizontal&#8221;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Label Name=&#8221;lblCategory&#8221; Width=&#8221;100&#8243;&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;TextBlock&gt;Category:&lt;\/TextBlock&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SelectedValue=&#8221;{Binding ElementName=Products, Path=SelectedItem.Category, Mode=TwoWay}&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Width=&#8221;140&#8243; \/&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/StackPanel&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;Button Height=&#8221;23&#8243; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HorizontalAlignment=&#8221;Right&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Name=&#8221;btnSaveChanges&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VerticalAlignment=&#8221;Bottom&#8221; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Width=&#8221;136&#8243; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Click=&#8221;btnSaveChanges_Click&#8221;&gt;Save Changes&lt;\/Button&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/StackPanel&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/StackPanel&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;\/Grid&gt; <br>&lt;\/Window&gt;<\/font><\/p>\n<p>If you open this up in the designer it should look something like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/ProductsCatalog.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/ProductsCatalog_thumb.png\" style=\"border-width: 0px\" title=\"ProductsCatalog\" alt=\"ProductsCatalog\" width=\"240\" border=\"0\" height=\"226\"><\/a>&nbsp;<\/p>\n<h4>Step 7 \u2013 Write the Code-Behind:<\/h4>\n<p>Next open up Window1.xaml.cs, the code behind file, and type in this code:<\/p>\n<p><font face=\"Courier New\">public partial class Window1 : Window <br>{ <br>&nbsp;&nbsp;&nbsp; ViewModel viewmodel = new ViewModel(); <br>&nbsp;&nbsp;&nbsp; public Window1() <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.cmbCategory.DataContext = viewmodel; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.grid1.DataContext = viewmodel; <br>&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp; private void btnSaveChanges_Click(object sender, RoutedEventArgs e) <br>&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; viewmodel.SaveChanges(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.grid1.DataContext = viewmodel; <br>&nbsp;&nbsp;&nbsp; } <br>}<\/font><\/p>\n<h4>Step 8 \u2013 Verify it is all working:<\/h4>\n<p>Now we are finished and you should be able to run the code, and see something like this:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/23\/2019\/02\/SampleAppRunning.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/odatateam\/wp-content\/uploads\/sites\/23\/2010\/01\/SampleAppRunning_thumb.png\" style=\"border-width: 0px\" title=\"SampleAppRunning\" alt=\"SampleAppRunning\" width=\"244\" border=\"0\" height=\"230\"><\/a> <\/p>\n<p>And you should be able select a Product and modify it, and once you are done making all your edits you should be able to submit them to the database by clicking \u2018Save Changes\u2019.<\/p>\n<h3>Summary:<\/h3>\n<p>As you can see from <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2009\/12\/17\/getting-started-with-the-data-services-update-for-net-3-5-sp1-part-1.aspx\">Part 1<\/a> &amp; this post it is very easy to install the <a href=\"http:\/\/blogs.msdn.com\/astoriateam\/archive\/2010\/01\/27\/data-services-update-for-net-3-5-sp1-available-for-download.aspx\">ADO.NET Data Services Update for .NET 3.5 SP1<\/a>, use it to create a <a href=\"https:\/\/odata.org\">OData V2<\/a> compliant Data Service and write a client application capable of leveraging that service.<\/p>\n<p>There will be more posts covering specific features of the Update over the next few weeks.<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/alexj\"><b>Alex James<\/b><\/a> <br><b>Program Manager, Data Frameworks Team, Microsoft<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Part 1 we created a Data Service that exposes V2 of the OData Protocol, in this post we will create a WPF application to consume our Data Service. Walkthrough: Step 1 \u2013 Update Code Generation Settings: The Data Services Update is basically a patch to .NET 3.5 SP1, so it can\u2019t break existing projects, [&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,48,91],"class_list":["post-1483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-odata","tag-ado-net-data-services","tag-odata","tag-wpf"],"acf":[],"blog_post_summary":"<p>In Part 1 we created a Data Service that exposes V2 of the OData Protocol, in this post we will create a WPF application to consume our Data Service. Walkthrough: Step 1 \u2013 Update Code Generation Settings: The Data Services Update is basically a patch to .NET 3.5 SP1, so it can\u2019t break existing projects, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1483","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=1483"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/posts\/1483\/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=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/categories?post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/odata\/wp-json\/wp\/v2\/tags?post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}