<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ADO.NET Data Services Team Blog : Tutorial</title><link>http://blogs.msdn.com/astoriateam/archive/tags/Tutorial/default.aspx</link><description>Tags: Tutorial</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>ADO.NET Data Services v1.5 CTP1 -- Data Binding Overview</title><link>http://blogs.msdn.com/astoriateam/archive/2009/03/21/ado-net-data-services-v1-5-ctp1-data-binding-overview.aspx</link><pubDate>Sun, 22 Mar 2009 00:34:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9496546</guid><dc:creator>dpblogs</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/astoriateam/comments/9496546.aspx</comments><wfw:commentRss>http://blogs.msdn.com/astoriateam/commentrss.aspx?PostID=9496546</wfw:commentRss><description>&lt;P&gt;This blog post is an introduction to the data binding capabilities we have added in Data Services v1.5 CTP1. Since this is a CTP release of this feature we eagerly look forward to hearing your feedback.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Introduction to Data Binding&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;In ADO.NET Data Services, it is now possible to generate client side types that implement the INotifyPropertyChanged and INotifyCollectionChanged interfaces. &lt;/P&gt;
&lt;P&gt;A new method has been added to the DataServiceQuery and QueryOperationResponse classes called ToObservableEntityCollection that will create an ObservableEntityCollection (extends ObservableCollection) that contains the results of an ADO.NET Data Services query. The ObservableEntityCollection supports two way binding. This means that any changes made to contents of the collection will be reflected on the state of the ADO.NET Data Services client context; any subsequent calls to SaveChanges() on that context will then execute those changes against the service.&lt;/P&gt;
&lt;P&gt;Here are some examples of different ways to create an ObservableEntityCollection using the ADO.NET Data Services client library. In all of these examples, the queries are being executed against a service named “nwsvc” that exposes two types: products and suppliers that have a one-to-many relationship.&lt;/P&gt;
&lt;P&gt;Example 1: Creating an ObservableEntityCollection of all products.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image002_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image002_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image002_thumb.jpg" width=555 height=22 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image002_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Example 2: Creating an ObservableEntityCollection of all products and their associated suppliers.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image004_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image004_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image004 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image004_thumb.jpg" width=558 height=18 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image004_thumb.jpg"&gt;&lt;/A&gt; &lt;BR&gt;Example 3: Creating an ObservableEntityCollection of all products and the associated suppliers from a LINQ Query.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image006_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image006_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image006 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image006_thumb.jpg" width=585 height=32 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image006_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Example 4: Creating a new ObservableEntityCollection of products. This creates a new empty collection of products without issuing a query against the service. New product objects can be created and added to this collection.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image008_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image008_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image008 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image008_thumb.jpg" width=556 height=20 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image008_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Example 5: Creating a ObservableEntityCollection of products from an asynchronous query.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image010_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image010_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image010 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image010_thumb.jpg" width=555 height=137 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image010_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Walkthrough&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The following is a walkthrough of using data binding in a WPF application. &lt;/P&gt;
&lt;P&gt;To get started, you'll want to download all of the required software I use in the walkthrough:&amp;nbsp; &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Visual Studio 2008 SP1 (&lt;A href="http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx" mce_href="http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx"&gt;here&lt;/A&gt;) &lt;/LI&gt;
&lt;LI&gt;ADO.NET Data Services v1.5 CTP1 (&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=3e3d4eaf-227b-4ad3-ad0d-3613db8aa9df&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=3e3d4eaf-227b-4ad3-ad0d-3613db8aa9df&amp;amp;displaylang=en"&gt;here&lt;/A&gt;) &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;B&gt;Step 1&lt;/B&gt;: Create an ADO.NET Data Service v1.5&lt;/P&gt;
&lt;P&gt;Create a new Web Application (named DatabindingDemo):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image012_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image012_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image012 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image012_thumb.jpg" width=351 height=240 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image012_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Our first data access related task is to generate the Entity Framework-based data access layer to the Northwind database.&amp;nbsp; Right click the ASP.NET project and select 'Add New Item', then select 'ADO.NET Entity Data Model'.&amp;nbsp; Name the new item nw.edmx:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image014_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image014_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image014 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image014_thumb.jpg" width=350 height=212 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image014_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;After clicking ‘Add’ on the screen above, a wizard will open to walk you through creating the Entity Data Model for the Northwind database. Use the default settings until you get to the point where you choose the database objects to include in the model. For this demo, choose only the Products and Suppliers tables.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image016_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image016_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image016 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image016_thumb.jpg" width=332 height=298 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image016_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Once you reach the ‘Choose Your Database Objects’ screen, select the two tables and click ‘Finish’. This will open the Entity Data Model designer view.&amp;nbsp; This view allows you to customize the generated conceptual data model. To learn more about the mapping capabilities of the Entity Framework, see &lt;A href="http://msdn.microsoft.com/en-us/magazine/cc700331.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc700331.aspx"&gt;here&lt;/A&gt;. For this demo rename the Suppliers entity to “Supplier” and the Products entity to “Product”.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image018_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image018_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image018 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image018_thumb.jpg" width=244 height=214 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image018_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Create a v1.5 CTP1-based ADO.NET Data Service over this model. To create the data service, right click the ASP.NET project and select 'Add New Item'.&amp;nbsp; Add an 'ADO.NET Data Service v1.5 CTP1' item called nw.svc&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image020_2.gif" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image020_2.gif"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image020 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image020_thumb.gif" width=320 height=195 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image020_thumb.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;This will generate a file (nw.svc.cs) which represents the skeleton of a v1.5 data service. All we need to do now is point the data service at the data model to be exposed as a REST-service and we’ll be set. The snippet below shows the 2 or so lines of code you need to write to do this. One thing to note is that a data service is locked down by default, so we need to take explicit steps to open access to it. For this simple application we’ll enable read and write access to the entire model quickly using the call to ‘SetEntitySetAccessRule’ shown below.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image022_2.gif" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image022_2.gif"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image022 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image022_thumb.gif" width=504 height=119 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image022_thumb.gif"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The data service is now created. To test this, run the project and navigate to the nw.svc file. You should see a listing as shown below that outlines all the entry points to the data service. If you don’t, &lt;A href="http://blogs.msdn.com/astoriateam/archive/2007/12/10/viewing-data-services-responses-using-atom-serialization-in-internet-explorer.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2007/12/10/viewing-data-services-responses-using-atom-serialization-in-internet-explorer.aspx"&gt;tweak your IE settings&lt;/A&gt; and reload.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image024_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image024_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image024 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image024_thumb.jpg" width=294 height=212 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image024_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 2: &lt;/B&gt;Enable data binding on the client.&lt;/P&gt;
&lt;P&gt;By default, the client side types generated by ADO.NET Data Services v1.5 CTP1 do not implement binding interfaces. To get client side types that do implement the binding interfaces, you have to tell the code generation library that you want client code that has binding enabled. To do this, set an environment variable before starting Visual Studio and then use Add Service Reference (ASR) to generate client proxy code. The environment variable to set is:&lt;/P&gt;
&lt;P&gt;set dscodegen_databinding=1&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Note&lt;/B&gt;: The use of this environment variable is further explained by the video embedded in &lt;A href="http://blogs.msdn.com/astoriateam/archive/2009/03/16/ado-net-data-services-v1-5-ctp1-now-available-for-download.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2009/03/16/ado-net-data-services-v1-5-ctp1-now-available-for-download.aspx"&gt;this&lt;/A&gt; blog post.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Note&lt;/B&gt;: It is also possible to generate proxy code that have binding enabled using DataSvcUtil.exe with the /binding flag.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image026_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image026_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image026 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image026_thumb.jpg" width=482 height=103 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image026_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 3&lt;/B&gt;: Create client proxy code with binding enabled.&lt;/P&gt;
&lt;P&gt;After setting the environment variable in step 2, open the solution you created in step 1 and create a new WPF project.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image028_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image028_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image028 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image028_thumb.jpg" width=402 height=259 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image028_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Once you have created a WPF client project, the next step is to generate client side types. To do this, find the DatabindingClient project in the solution explorer, right-click the project and select &lt;I&gt;Add Service Reference.. .&lt;/I&gt;In the Add Service Reference dialog, click the &lt;I&gt;Discover&lt;/I&gt; button. The nw.svc service will show up in the &lt;I&gt;Service&lt;/I&gt; window. Enter NorthwindService as the Namespace value and select OK. This wizard will generate a set of client side types that can be used to interact with the service created in step 1.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image030_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image030_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image030 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image030_thumb.jpg" width=378 height=306 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image030_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;If this step is done correctly, you will see a new NorthwindService node under the Service References Node in the solution explorer. As well, you will see a reference to Microsoft.Data.Services.Client in the references node; if you do not see the reference to Microsoft.Data.Services.Client or you see a reference to System.Data.Services.Client go to the ADO.NET Data Services blog and read &lt;A href="http://blogs.msdn.com/astoriateam/archive/2009/03/16/ado-net-data-services-v1-5-ctp1-now-available-for-download.aspx" mce_href="http://blogs.msdn.com/astoriateam/archive/2009/03/16/ado-net-data-services-v1-5-ctp1-now-available-for-download.aspx"&gt;this&lt;/A&gt; post about enabling ADO.NET Data Services v1.5 features in Visual Studio and then repeat the Add Service Reference Step.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image032_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image032_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image032 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image032_thumb.jpg" width=224 height=298 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image032_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The next step is to create a new instance of the ADO.NET Data Services client context and connect to the service created in step 1. To do this, add the following code to the Window1.xaml.cs file to create a connection to the service; making sure to replace the host and port number with the values for your service.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image034_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image034_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image034 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image034_thumb.jpg" width=511 height=82 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image034_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The next step is to create an interface that you can bind the result of a query to. The service you created in step 1 exposes a set of Suppliers and a set of Products from the Northwind database with a one-to-many relationship between them. The XAML code below will create two listviews, one to display the suppliers and another to display the products associated with the current supplier selected in the first view. This type of binding is called master-detail binding. &lt;/P&gt;
&lt;P&gt;The code below uses standard WPF binding semantics. The ItemsSource of the supplierView is set to “{Binding}”, this will cause the listview to bind to the collection of items that are supplied as the data context of the supplierViewGrid; in this case the collection of items will be a collection of supplier objects. The columns of the supplierView are each bound to a property of the supplier object through the DisplayMemberBinding="{Binding Path=SupplierID}"/&amp;gt; tag. &lt;/P&gt;
&lt;P&gt;The second listview, productsView, is bound to the Products property of the supplier objects by the ItemsSource="{Binding Products}" tag. &lt;/P&gt;
&lt;P&gt;By supplying the IsSynchronizedWithCurrentItem="True" tag on the listview, you are taking advantage of the feature WPF has to automatically display the items in the second list view (products) that are associated with the currently selected item in the first list view (suppliers).&lt;/P&gt;
&lt;P&gt;Paste the following code snippet into the window1.xaml file:&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid Name="supplierViewGrid"&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ListView ItemsSource="{Binding}" Margin="25,11,33,145" Name="supplierView"&lt;/P&gt;
&lt;P&gt;IsSynchronizedWithCurrentItem="True"&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ListView.View&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="ID" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;Path=SupplierID}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="Name" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;Path=CompanyName}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="Address" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;Path=Address}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="City" DisplayMemberBinding="{Binding Path=City}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="Region" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;Path=Region}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/GridView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/ListView.View&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/ListView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ListView Margin="25,213,33,0" Name="productsView" ItemsSource="{Binding Products}"&lt;/P&gt;
&lt;P&gt;IsSynchronizedWithCurrentItem="True" Height="97" VerticalAlignment="Top"&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ListView.View&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="ID" DisplayMemberBinding="{Binding ProductID}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="Name" DisplayMemberBinding="{Binding ProductName}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="QuantityPerUnit" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;QuantityPerUnit}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="Price" DisplayMemberBinding="{Binding UnitPrice}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;GridViewColumn Header="InStock" DisplayMemberBinding="{Binding&lt;/P&gt;
&lt;P&gt;UnitsInStock}"/&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/GridView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/ListView.View&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/ListView&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;Edit the following attributes of your window: Height="382" Width="584" to properly display the controls.&lt;/P&gt;
&lt;P&gt;This will create a WPF interface that looks like this:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image036_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image036_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image036 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image036_thumb.jpg" width=391 height=257 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image036_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The final step to enable binding to these WPF controls is to set the DataContext of the grid in the window you just created to the result of a query for suppliers from the service created in step 1. This is done by executing a standard ADO.NET Data Services query on the context for the set of suppliers and then adding a call to ToObservableEntityCollection() to the result of the query. The ToObservableEntityCollection() method will execute the query against the service and return the result as an ObservableEntityCollection of entities. The entities in this collection will implement INotifyPropertyChanged and INotifyCollectionChanged. To do this, add the following code to the constructor for the window:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image038_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image038_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image038 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image038_thumb.jpg" width=507 height=56 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image038_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Once this is complete, compile the project and run it. The result should be:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image040_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image040_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image040 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image040_thumb.jpg" width=398 height=263 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image040_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 4: Two-way Binding&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Up to this point in the walkthrough, you have set up a service, created a WPF client and bound the result of a query to the service to a pair of listview controls in the client. This type of binding you have done so far has all been one-way binding. The ObservableEntityCollection you used at the end of step 3 also supports two-way binding. This means that any changes made to the collection or items in the collection will propagate to the service when a call to SaveChanges() is made on the context. &lt;/P&gt;
&lt;P&gt;This final step will walk you through adding buttons that will add and remove items to the collection of products and take advantage of two-way binding to have those changes propagate to the service and the backing northwind database.&lt;/P&gt;
&lt;P&gt;To start, add the following XAML code to the window1.xaml file to create three buttons to that will add and remove a product from the list of products and save the changes to the service.&lt;/P&gt;
&lt;P&gt;&amp;lt;Button Height="24" HorizontalAlignment="Left" Margin="411,0,0,4"&lt;/P&gt;
&lt;P&gt;Name="addButton" VerticalAlignment="Bottom" Width="28" Click="addButton_Click"&amp;gt;+&amp;lt;/Button&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Button Height="24" HorizontalAlignment="Right" Margin="0,0,89,4"&lt;/P&gt;
&lt;P&gt;Name="deleteButton" VerticalAlignment="Bottom" Width="28" Click="deleteButton_Click"&amp;gt;-&amp;lt;/Button&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Button Height="24" HorizontalAlignment="Right" Margin="0,0,33,4"&lt;/P&gt;
&lt;P&gt;Name="saveButton" VerticalAlignment="Bottom" Width="50" Click="saveButton_Click"&amp;gt;Save&amp;lt;/Button&amp;gt;&lt;/P&gt;
&lt;P&gt;After adding this code the client application will be: &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image042_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image042_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image042 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image042_thumb.jpg" width=437 height=289 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image042_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The next step is to handle the click events on the new buttons and add or remove the currently select product in the list. The first thing we will need is a new product window to input the property values of a new product when one is created. To do this, create a new WPF window in your client project called ProductWindow.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image044_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image044_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image044 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image044_thumb.jpg" width=437 height=263 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image044_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;After creating the window, we need to set up the product window to bind to a single instance of the product class. To configure binding in the product window, you will use the same WPF binding method you used for the supplier window, except this window will bind to a single object and not a collection of objects. Add the following XAML code into the ProductWindow.xaml:&lt;/P&gt;
&lt;P&gt;Title="Product" Height="206" Width="296"&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid x:Name="productGrid"&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Grid.ColumnDefinitions&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ColumnDefinition Width="171*" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;ColumnDefinition Width="159*" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/Grid.ColumnDefinitions&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Label Height="26" Margin="12,17,68,0" Name="nameLabel"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Top"&amp;gt;Name:&amp;lt;/Label&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Label Margin="12,49,6,0" Name="quantityLabel" Height="26"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Top"&amp;gt;Quantity Per Unit:&amp;lt;/Label&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Label Margin="12,78,68,64" Name="priceLabel"&amp;gt;Price:&amp;lt;/Label&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Label Height="26" Margin="12,0,68,35" Name="inStockLabel"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Bottom"&amp;gt;InStock:&amp;lt;/Label&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;TextBox Height="23" Margin="0,23,28.018,0" Name="textBox1"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Top" Text="{Binding ProductName}" Grid.Column="1" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;TextBox Margin="0,52,28.018,0" Name="textBox2" Text="{Binding&lt;/P&gt;
&lt;P&gt;QuantityPerUnit}" Height="23" VerticalAlignment="Top" Grid.Column="1" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;TextBox Margin="0,81,28.018,64" Name="textBox3" Text="{Binding&lt;/P&gt;
&lt;P&gt;UnitPrice}" Grid.Column="1" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;TextBox Height="23" Margin="0,0,28.018,35" Name="textBox4"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Bottom" Text="{Binding UnitsInStock}"&lt;/P&gt;
&lt;P&gt;Grid.Column="1" /&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;Button Height="23" Margin="19.018,0,61,6" Name="okButton"&lt;/P&gt;
&lt;P&gt;VerticalAlignment="Bottom" Grid.Column="1"&lt;/P&gt;
&lt;P&gt;Click="okButton_Click"&amp;gt;OK&amp;lt;/Button&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;lt;/Grid&amp;gt;&lt;/P&gt;
&lt;P&gt;Next add the following code to the ProductWindow.xaml.cs file to set the data context to a single product and handle the ok button click event:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image046_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image046_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image046 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image046_thumb.jpg" width=523 height=240 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image046_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The final step is to handle the add, remove, and save button click events in the supplier window. Add the following code to the Window1.xaml.cs file.&lt;/P&gt;
&lt;P&gt;Add the following code to the addButton_Click event to create a new product when the add button is selected. The following code creates a new Product object, adds it to the list of products for the currently selected supplier, and creates a new product window for the user to input the property values for the new product. &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image048_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image048_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image048 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image048_thumb.jpg" width=521 height=155 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image048_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Add the following code to handle the click event on the delete button. This method finds the supplier that represents the currently selected supplier in the list view. It then removes the currently selected product from that supplier’s collection of products. This operation gets translated into a delete operation on the product object in the service. After the save button is clicked, the product entry that has been removed will be deleted from the backing northwind database.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image050_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image050_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image050 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image050_thumb.jpg" width=523 height=82 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image050_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Add the following code to handle the save button click. This button calls SaveChanges on the context which will cause any operations that have been performed on the context to be sent to the service.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image052_2.jpg" mce_href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image052_2.jpg"&gt;&lt;IMG style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px" border=0 alt=clip_image052 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image052_thumb.jpg" width=532 height=77 mce_src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServ.5CTP1DataBindingOverview_CC93/clip_image052_thumb.jpg"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Your project is now complete. You can run the form and use the buttons to add and remove items from the collection of products. When you make a change you then click the save button to persist the changes to the service.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Providing Feedback&lt;/B&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;We have created a new forum dedicated to providing feedback on "pre-release" versions of data services such as this CTP.&amp;nbsp; Please direct all your questions and comments about this feature this new forum which is available at: (&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads" mce_href="http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads"&gt;http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads&lt;/A&gt;).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Note: The forum intended for questions on currently shipping versions of ADO.NET Data Services is still available at: &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/"&gt;(http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/&lt;/A&gt; )&lt;/P&gt;
&lt;P&gt;We look forward to hearing your feedback.&lt;/P&gt;
&lt;P&gt;Shayne Burgess&lt;/P&gt;
&lt;P&gt;ADO.NET Data Services, Program Manager&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9496546" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/astoriateam/archive/tags/Tutorial/default.aspx">Tutorial</category></item><item><title>ADO.NET Data Services v1.5 CTP1 - Server Driven Paging</title><link>http://blogs.msdn.com/astoriateam/archive/2009/03/19/ado-net-data-services-v1-5-ctp1-server-driven-paging.aspx</link><pubDate>Thu, 19 Mar 2009 19:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9490410</guid><dc:creator>dpblogs</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/astoriateam/comments/9490410.aspx</comments><wfw:commentRss>http://blogs.msdn.com/astoriateam/commentrss.aspx?PostID=9490410</wfw:commentRss><description>&lt;P&gt;This post is a drill down into the Server Driven Paging (SDP) feature added in data services v1.5 CTP1.&amp;nbsp; Since this is the first CTP release of this feature we look forward to hearing your feedback.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What is Server Driven Paging?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This feature is best described by example.&amp;nbsp; If you had a data service that exposes photos, you would likely want to limit the total number of photos a single request to the service can retrieve because the total collection of photos may be very large.&amp;nbsp; This feature allows a service author to set per collection limits on the total number of entities returned for each request.&amp;nbsp; In addition to limiting the number of photos returned per request, the server provides the client a "next link" which is simply a URI specifying how to continue retrieving the rest of the entities in the collection not returned by the first request.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;For those familiar with AtomPub (&lt;A href="http://www.ietf.org/rfc/rfc5023.txt"&gt;IETF RFC 5023&lt;/A&gt;, section 10.1), this feature adds support for AtomPub &amp;lt;link rel="next" ...&amp;gt; elements to the data service runtime.&amp;nbsp;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;For CTP1 we've included server side support for this feature only.&amp;nbsp; Client library support will likely come in a future CTP.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Feature Walkthrough&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The remainder of this post is a step-by-step walkthrough describing how to enable and work with the Server Driven Paging feature in a data service.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;To get started, you'll want to download all of the required software I use in the walk through:&amp;nbsp; &lt;/P&gt;
&lt;UL&gt;
&lt;UL&gt;
&lt;LI&gt;Visual Studio 2008 SP1 (&lt;A href="http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx"&gt;here&lt;/A&gt;) &lt;/LI&gt;
&lt;LI&gt;ADO.NET Data Services v1.5 CTP1 (&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=3e3d4eaf-227b-4ad3-ad0d-3613db8aa9df"&gt;here&lt;/A&gt;) &lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;
&lt;P&gt;The steps we’ll follow in this walkthrough are noted below.&amp;nbsp; If you are already familiar with ADO.NET Data Services v1 you may want to skip down to Step 2.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 1&lt;/B&gt;:&amp;nbsp; Create an ASP.NET Web Application project and create the data model to be exposed by an ADO.NET Data Service using the Entity Framework (EF) and SQL Server. Note: Any data source (EF, custom provider, etc) supported by ADO.NET Data Services could be used.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Step 2&lt;/STRONG&gt;: Create a v1.5 ADO.NET Data Service which exposes the data model created in step 1.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 3&lt;/B&gt;: Enable Server Driven Paging limits on the data service created in step 2.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Step 1: Create the Project &amp;amp; Data Model&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;Nothing new yet, simply create a new Web Application (named SDPDemo).&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/NewWebApp_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=NewWebApp src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/NewWebApp_thumb.jpg" width=281 height=189&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Our first data access related task is to generate the Entity Framework-based data access layer to the Northwind database.&amp;nbsp; Right click the ASP.NET project and select 'Add New Item', then select 'ADO.NET Entity Data Model'.&amp;nbsp; Name the new item nw.edmx:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_2.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb.png" width=413 height=249&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;After clicking ‘Add’ on the screen above, a wizard will open to walk you through creating the Entity Data Model for the Northwind database. Use the default settings (selecting the Northwind DB along the way) and click the ‘Next’ button until you reach the screen shown below:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_4.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_1.png" width=264 height=249&gt;&lt;/A&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Once you reach the ‘Choose Your Database Objects’ screen, select all the Tables and click ‘Finish’. This will open the Entity Data Model designer view.&amp;nbsp; This view allows you to customize the generated conceptual data model. To learn more about the mapping capabilities of the Entity Framework, see &lt;A href="http://msdn.microsoft.com/en-us/magazine/cc700331.aspx"&gt;here&lt;/A&gt;. For this demo we’ll just use the default model created by the wizard without any customizations.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/clip_image002_2.jpg"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=clip_image002 src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/clip_image002_thumb.jpg" width=267 height=167&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Step 2: Create the v1.5 CTP1-based ADO.NET Data Service&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;The next step is to create our v1.5 CTP1-based ADO.NET Data Service which we'll subsequently set Server Driven Paging limits on.&lt;/P&gt;
&lt;P&gt;To create the data service, right click the ASP.NET project and select 'Add New Item'.&amp;nbsp; Add an 'ADO.NET Data Service v1.5 CTP1' item called nw.svc:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_6.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_2.png" width=398 height=241&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;This will generate a file (nw.svc.cs) which represents the skeleton of a v1.5 data service. All we need to do now is point the data service at the data model to be exposed as a REST-service and we’ll be set. The snippet below shows the 2 or so lines of code you need to write to do this. One thing to note is that a data service is locked down by default, so we need to take explicit steps to open access to it. For this simple application we’ll enable read and write access to the entire model quickly using the call to ‘SetEntitySetAccessRule’ shown below.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_8.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_3.png" width=429 height=98&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;That’s it, our data service is now created. To test this, run the project and navigate to the nw.svc file. You should see a listing as shown below that outlines all the entry points to the data service. If you don’t, &lt;A href="http://blogs.msdn.com/astoriateam/archive/2007/12/10/viewing-data-services-responses-using-atom-serialization-in-internet-explorer.aspx"&gt;tweak your IE settings&lt;/A&gt; and reload.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_10.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_4.png" width=244 height=168&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Step 3: Set Server Driven Paging Limits&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;At this point we have a working data service and are ready to configure the Server Driven Paging limits for the service.&amp;nbsp; For example, to limit the number of Customer entities the data service will return per request to 4, we would add the following call to 'SetResourceSetPageSize' to our data service:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_12.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_5.png" width=424 height=226&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;If you view the nw.svc file in the browser and navigate to the &lt;EM&gt;nw.svc/Customers&lt;/EM&gt; endpoint of the service you should now only see four customer entities returned even though the Northwind DB has many more than four customers in it.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The next thing to notice is the response from the data service includes a "next link" which is a URI indicating how a client can continue retrieving the rest of the entities in the collection not returned by the first request.&amp;nbsp; The images below show the AtomPub and JSON representations returned (and the associated "next links") when querying the nw.svc/Customers URI.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_14.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_6.png" width=391 height=131&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_16.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image src="http://blogs.msdn.com/blogfiles/astoriateam/WindowsLiveWriter/ADO.NETDataServi.5CTP1ServerDrivenPaging_107DE/image_thumb_7.png" width=390 height=259&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;Sending an HTTP GET request to the "next link" in the above listing would allow the client to continue making progress towards obtaining the entire set of Customer entities.&amp;nbsp; In this example a GET request sent to the URI &lt;EM&gt;nw.svc/Customers?$skiptoken='AROUT' &lt;/EM&gt;would retrieve the next four Customers (sorted by key) from the data service after those in the above listing.&lt;/P&gt;
&lt;P&gt;This feature works in conjunction with all query requests (arbitrary filters, result ordering, etc).&amp;nbsp; For example, if a GET request is sent to the URI: &lt;EM&gt;nw.svc/Customers?$filter=City eq 'London'&amp;amp;$orderby=PostalCode , &lt;/EM&gt;the results returned will be the first four Customers in London sorted by PostalCode and the "next link" returned will be equal to: &lt;EM&gt;nw.svc/Customers?$filter=City eq 'London'&amp;amp;$orderby=PostalCode&amp;amp;$skiptoken='WA1 1DP','AROUT'.&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;It is important to note this feature is a &lt;STRONG&gt;server driven &lt;/STRONG&gt;paging mechanism which allows a data service to gracefully return partial sets to a client.&amp;nbsp; If a client application knows it wants a subset of the total number of entities in an entity set (perhaps to bind to a paged grid UI control) then it should use the &lt;STRONG&gt;client driven&lt;/STRONG&gt; paging query string options ($top and $skip) available starting with the v1 data services framework.&amp;nbsp; For additional information on $top and $skip see this "&lt;A href="http://msdn.microsoft.com/library/cc907912.aspx"&gt;Using ADO.NET Data Services&lt;/A&gt;" (v1) whitepaper.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Providing Feedback&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;We have created a new forum dedicated to providing feedback on "pre-release" versions of data services such as this CTP.&amp;nbsp; Please direct all your questions and comments about this feature to this new forum which is available at: (&lt;A title=http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads href="http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads" mce_href="http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads"&gt;http://social.msdn.microsoft.com/Forums/en-US/dataservices/threads&lt;/A&gt;).&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Note: The forum intended for questions on currently shipping versions of ADO.NET Data Services is still available at: &lt;A title=http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/ href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/"&gt;(http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/threads/&lt;/A&gt; )&lt;/P&gt;
&lt;P&gt;We look forward to hearing your feedback.&lt;/P&gt;
&lt;P&gt;-Mike Flasko&lt;/P&gt;
&lt;P&gt;ADO.NET Data Services, Program Manager&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9490410" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/astoriateam/archive/tags/Tutorial/default.aspx">Tutorial</category></item></channel></rss>