<?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>With Great Power comes Great Response.write("Ability") : Demo</title><link>http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx</link><description>Tags: Demo</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>ADO.NET Data Services : Efficient Error Handling across Application Tiers</title><link>http://blogs.msdn.com/phaniraj/archive/2009/11/14/ado-net-data-services-efficient-error-handling-across-application-tiers.aspx</link><pubDate>Sat, 14 Nov 2009 04:43:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9922386</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9922386.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9922386</wfw:commentRss><description>&lt;p&gt;While developing an application that spans multiple tiers , it is important that you be able to flow error information through the tiers without losing    &lt;br /&gt;any context or details in the tiers. With ADO.NET Data Services , we have an error contract which guarantees that all errors thrown from the Data Service ,     &lt;br /&gt;wrapped inside a &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.dataserviceexception.aspx"&gt;DataServiceException&lt;/a&gt; , will be represented in a standard way on the wire when we send the error down to the client.     &lt;br /&gt;    &lt;br /&gt;For example , consider the Query Interceptor shown below . &lt;/p&gt;  &lt;pre class="csharpcode"&gt;[QueryInterceptor(&lt;span class="str"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; Expression&amp;lt;Func&amp;lt;Customers, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt;&amp;gt; OnQueryCustomers()
{
        &lt;span class="kwrd"&gt;string&lt;/span&gt; loggedInUser = HttpContext.Current.User.Identity.Name;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (UserHasAccessToSet(&lt;span class="str"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;, loggedInUser))
        {
            &lt;span class="rem"&gt;//Filter Expression goes here&lt;/span&gt;
            &lt;span class="kwrd"&gt;return&lt;/span&gt; entity =&amp;gt; &lt;span class="kwrd"&gt;true&lt;/span&gt;;
        }
        &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="rem"&gt;//User does not have access to '/Customers' , throw AccessViolationException&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceException(403,
                &lt;span class="str"&gt;&amp;quot;Forbidden&amp;quot;&lt;/span&gt;,
                String.Format(&lt;span class="str"&gt;&amp;quot;User '{0}' cannot request data from '{1}' table&amp;quot;&lt;/span&gt;, loggedInUser, &lt;span class="str"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;),
                &lt;span class="str"&gt;&amp;quot;en-US&amp;quot;&lt;/span&gt;);
        }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;When the Astoria server runtime throws the above exception , the 403 value specified above&amp;#160; gets turned into the response status code of the request 
  &lt;br /&gt;which caused this exception.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Ado.netDataServicesEfficientErrorHandlin_A066/StatusCodeInFiddler_1.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="StatusCodeInFiddler" border="0" alt="StatusCodeInFiddler" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Ado.netDataServicesEfficientErrorHandlin_A066/StatusCodeInFiddler_thumb_1.png" width="402" height="79" /&gt;&lt;/a&gt;&amp;#160; &lt;/p&gt;

&lt;p&gt;and the error message is serialized out to be in this format : &lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;standalone&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;yes&amp;quot;&lt;/span&gt; ?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Forbidden&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;xml:lang&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;User 'NoPermissions' cannot request data from 'Customers' table&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;At this point , the service has not lost any information that the service author intended to convey to a service consumer. 
  &lt;br /&gt;

  &lt;br /&gt;Now , lets consider the client library and how it handles this case. 

  &lt;br /&gt;Lets consider a query for the “Customers” set to which the currently logged-in user doesn't have permissions.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Customers customerEntity &lt;span class="kwrd"&gt;in&lt;/span&gt; northwindContext.CreateQuery&amp;lt;Customers&amp;gt;(&lt;span class="str"&gt;&amp;quot;Customers&amp;quot;&lt;/span&gt;) ) {
 &lt;span class="rem"&gt;//Do something with the customerEntity here&lt;/span&gt;
}&lt;/pre&gt;

&lt;p&gt;In this case, running the above code&amp;#160; would result in a DataServiceQueryException being thrown.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;System.Data.Services.Client.DataServiceQueryException: 
  An error occurred while processing this request. ---&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;        &lt;br /&gt;     System.Data.Services.Client.DataServiceClientException: 
      &lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;standalone&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;yes&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;        &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Forbidden&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;xml:lang&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;User 'NoPermissions' cannot request data from 'Customers' table&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;      &amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Note that the DataServiceException thrown by the server is now set to the Message property of the InnerException of the DataServiceQueryException. 
  &lt;br /&gt;We do not de-serialize the DataServiceException into an exception type on the client side. 

  &lt;br /&gt;By default , since the exception is now a string on the client side , you don’t have direct&amp;#160; access to the information contained inside the Exception. 

  &lt;br /&gt;The information is all still there , just not easily accessible anymore. Since the error contract is &lt;a href="http://msdn.microsoft.com/en-us/library/dd541497(PROT.10).aspx"&gt;documented&lt;/a&gt; and follows a standard pattern , 

  &lt;br /&gt;we can easily write a visitor that de-serializes an exception object from the “Message” property&amp;#160; of the Inner Exception.&lt;/p&gt;

&lt;p&gt;One such de-serializer for Error contracts is shown at the bottom of this post 
  &lt;br /&gt;It contains two methods : 

  &lt;br /&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;TryParse : which takes in an exception caused during Querying or updating via the client library and 
    &lt;br /&gt;returns a DataServiceException that was thrown by the Server &lt;/li&gt;

  &lt;li&gt;Throw : which takes in an exception caused during Querying or updating via the client library and 
    &lt;br /&gt;re-throws the DataServiceException that was thrown by the Server &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;script src="http://gist.github.com/227246.js"&gt;&lt;/script&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9922386" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Components/default.aspx">Components</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category></item><item><title>Using the ADO.NET Data Services Silverlight client library in x-domain and out of browser scenarios – II (Forms Authentication)</title><link>http://blogs.msdn.com/phaniraj/archive/2009/09/10/using-the-ado-net-data-services-silverlight-client-library-in-x-domain-and-out-of-browser-scenarios-ii-forms-authentication.aspx</link><pubDate>Thu, 10 Sep 2009 02:20:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9893382</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9893382.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9893382</wfw:commentRss><description>&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;A href="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx" mce_href="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx"&gt;Click here to download sample application&lt;/A&gt;&lt;/EM&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the ADO.NET Data Services Silverlight client library in x-domain and out of browser scenarios – II (Forms Authentication) &lt;BR&gt;In this blog post, we will talk about using the Silverlight Client Library against a Data Service that is secured with Asp.Net Forms Authentication &lt;BR&gt;In short, the whole process of authenticating against a Forms Authentication protected Data Service looks like this. &lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_8.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_8.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_3.png" width=729 height=303 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_3.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;H3&gt;Server Setup &lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;Setup Forms Authentication on the Data Service Server &lt;/LI&gt;
&lt;LI&gt;Enable the WCF Authentication Service by following the reference here : &lt;A href="http://msdn.microsoft.com/en-us/library/bb398990.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398990.aspx"&gt;How to: Enable the WCF Authentication Service&lt;/A&gt; &lt;/LI&gt;
&lt;LI&gt;Exclude the following resources from requiring authentication , &lt;/LI&gt;&lt;/OL&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;3.1 The WCF Authentication Service &lt;BR&gt;3.2 The ClientAccessPolicy.xml File &lt;BR&gt;Ex:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;&amp;lt;!-- The ClientAccessPolicy.xml file is required for the client to confirm if the server allows X-Domain callers.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;       This should be downloadable without authenticating--&amp;gt;&lt;/SPAN&gt;
 &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt; &lt;SPAN class=attr&gt;path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="clientaccesspolicy.xml"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;allow&lt;/SPAN&gt; &lt;SPAN class=attr&gt;users&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="*"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
 &lt;SPAN class=rem&gt;&amp;lt;!--This should be downloadable without authenticating.--&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt; &lt;SPAN class=attr&gt;path&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="AuthenticationService.svc"&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=kwrd&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class=html&gt;allow&lt;/SPAN&gt; &lt;SPAN class=attr&gt;users&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;="*"&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;/&amp;gt;&lt;/SPAN&gt;
      &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;authorization&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;system.web&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;&amp;lt;/&lt;/SPAN&gt;&lt;SPAN class=html&gt;location&lt;/SPAN&gt;&lt;SPAN class=kwrd&gt;&amp;gt;&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;4. If the DataServiceHost does not have a global.asax file, add one to the project. &lt;BR&gt;5. In the Global.asax file, we need to listen on the &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx"&gt;AuthenticationService.CreatingCookie&lt;/A&gt; event to customize the FormsAuth Cookie that the service creates.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Why do we need to customize the FormsAuth cookie? &lt;BR&gt;&lt;/B&gt;The WCF Authentication service by default creates &lt;A href="http://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.web.httpcookie.httponly.aspx"&gt;HTTPOnly&lt;/A&gt; Cookies. &lt;BR&gt;This means that the cookie isn’t accessible by client-script. &lt;BR&gt;It generally isn’t a problem when the client application is running in the same domain as the Website, &lt;BR&gt;as the browser handles cookie management for us transparently. &lt;BR&gt;When the client is not in the same domain as the Website, and we use the ClientHttpWebRequest networking stack, &lt;BR&gt;we are unable to access any cookies marked as HttpOnly. &lt;BR&gt;To work around this limitation, we recreate the FormsAuth cookie with HttpOnly set to false in the CreatingCookie event handler. &lt;BR&gt;For more details: &lt;A href="http://msdn.microsoft.com/en-us/library/bb398778.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb398778.aspx"&gt;How to: Customize the Authentication Cookie from the WCF Authentication Service&lt;/A&gt; &lt;BR&gt;Example code:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;protected&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Application_Start(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, EventArgs e)
{
&lt;SPAN class=rem&gt;//Handle the CreatingCookie event so that we can create a custom cookie with HttpOnly set to false.&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//AuthenticationService.CreatingCookie on MSDN :&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//http://msdn.microsoft.com/enus/library/system.web.applicationservices.authenticationservice.creatingcookie.aspx&lt;/SPAN&gt;
AuthenticationService.CreatingCookie += &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; EventHandler&amp;lt;CreatingCookieEventArgs&amp;gt;(CreateSilverlightCompatibleHttpCookie);
}&lt;BR&gt;&lt;BR&gt;&lt;BR&gt;&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Creates a HttpCookie that can be read by the managed CookieContainer in ClientHttpWebRequest in Silverlight&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="sender"&amp;gt;The calling context for this event&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="e"&amp;gt;a property bag containing useful information about the HttpCookie to create&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; CreateSilverlightCompatibleHttpCookie(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, System.Web.ApplicationServices.CreatingCookieEventArgs e)
{
  &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; cookieVersion = 1;
  &lt;SPAN class=rem&gt;//The time at which the cookie was issued by the server&lt;/SPAN&gt;
  DateTime cookieIssueDate = DateTime.Now;
  &lt;SPAN class=rem&gt;//The relative time from now when the cookie will expire and the client will have to re-authenticate.&lt;/SPAN&gt;
  DateTime cookieExpiryDate = DateTime.Now.AddMinutes(30);
  &lt;SPAN class=rem&gt;//The Forms Auth ticket which uniquely identifies a user &lt;/SPAN&gt;
  &lt;SPAN class=rem&gt;//FormsAuthenticationTicket on MSDN : http://msdn.microsoft.com/en-us/library/system.web.security.formsauthenticationticket.aspx&lt;/SPAN&gt;
  FormsAuthenticationTicket ticket = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; FormsAuthenticationTicket
                (cookieVersion,
                 e.UserName,
                 cookieIssueDate,
                 cookieExpiryDate,
                 e.IsPersistent, &lt;SPAN class=rem&gt;/*Indicates whether the authentication cookie should be retained beyond the current session*/&lt;/SPAN&gt;
                 e.CustomCredential,
                 FormsAuthentication.FormsCookiePath);
 &lt;SPAN class=rem&gt;//Creates a string containing an encrypted forms-authentication ticket suitable for use in an HTTP cookie.&lt;/SPAN&gt;
 &lt;SPAN class=rem&gt;//FormsAuthentication.Encrypt on MSDN : http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.encrypt.aspx&lt;/SPAN&gt;
  &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; encryptedTicket = FormsAuthentication.Encrypt(ticket);
  HttpCookie cookie = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
  &lt;SPAN class=rem&gt;//set HttpOnly to false so that the managed CookieContainer can read the FormsAuth cookie from the response.&lt;/SPAN&gt;
  cookie.HttpOnly = &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;;
  cookie.Expires = cookieExpiryDate;
  HttpContext.Current.Response.Cookies.Add(cookie);
  e.CookieIsSet = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
 }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;H3&gt;Silverlight Client Setup&lt;/H3&gt;
&lt;P&gt;We will follow an adapter pattern which is responsible for logging in the user and injecting the FormsAuth cookie as the client library makes requests. &lt;BR&gt;To start with,&lt;B&gt; add a Service reference to the WCF Authentication service in the Silverlight Client application or use the one in the sample.&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;The FormsAuthAdapter will use the client side proxy generated for the WCF Authentication service to login the user &lt;BR&gt;and hook into any attached DataServiceContext instance’s SendingRequest event to inject the FormsAuth cookie. &lt;BR&gt;An instance of the FormsAuthenticationAdapter is declared at the application level.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;partial&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; App : Application
{
&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// FormsAuthenticationAdapter instance to manage authentication against a WCF Authentication Service&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;static&lt;/SPAN&gt; FormsAuthenticationAdapter FormsAuthAdapter;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;This is initialized when the Application starts.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Application_Startup(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, StartupEventArgs e)
{
&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; authServiceUri = String.Empty;
&lt;SPAN class=rem&gt;//extract the AuthenticationService Uri from the App.XAML file&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (&lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Resources.Contains(&lt;SPAN class=str&gt;"AuthenticationServiceUri"&lt;/SPAN&gt;))
{
authServiceUri = &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.Resources[&lt;SPAN class=str&gt;"AuthenticationServiceUri"&lt;/SPAN&gt;].ToString();
}
FormsAuthAdapter = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; FormsAuthenticationAdapter(&lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; Uri(authServiceUri, UriKind.RelativeOrAbsolute));
&lt;SPAN class=rem&gt;//The FormsAuthCookieName  should be the same value as declared in the Web.config of the server&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//ex: If your web.config on the server requiring Forms Authentication is :&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//&amp;lt;authentication mode="Forms"&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//  &amp;lt;forms loginUrl="LoginForm.aspx" name=".ASPXFormsAUTH" protection="All" path="/" /&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;//&amp;lt;/authentication&amp;gt;&lt;/SPAN&gt;
    FormsAuthAdapter.FormsAuthCookieName = &lt;SPAN class=str&gt;".ASPXFormsAUTH"&lt;/SPAN&gt;;
    &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.RootVisual = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; MainPage();
    &lt;SPAN class=rem&gt;//Uncomment the below 2 lines to show the Loginwindow on application startup&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;//LoginWindow login = new LoginWindow();&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;//login.Show();&lt;/SPAN&gt;
}&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;This is what our client application looks like: &lt;BR&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_2.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_2.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb.png" width=580 height=455 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;As you can see, along with the “Install me” button, we now have a “Login” button.&lt;/P&gt;
&lt;P&gt;When the page loads, we attach an instance of the DataServiceContext which we want to get the FormsAuth Cookie injected while &lt;BR&gt;making requests to the Data Service.&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=rem&gt;//Attach the DataServiceContext instance so that we can inject the FormsAuth cookie for each request&lt;/SPAN&gt;
App.FormsAuthAdapter.Attach(publicationContext);
Where the Attach Method’s signature &lt;SPAN class=kwrd&gt;is&lt;/SPAN&gt; :
&lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Injects the FormsAuth cookie when the contextInstance makes a request to the DataService&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="contextInstance"&amp;gt;The DataServiceContext instance to observe&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; Attach(DataServiceContext contextInstance)&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;Clicking the login button on the main page opens up a ChildWindow instance that we created which emulates the Login Screen. &lt;/P&gt;
&lt;P&gt;Login button click handler:&lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginUser(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, RoutedEventArgs e)
{
    LoginWindow login = &lt;SPAN class=kwrd&gt;new&lt;/SPAN&gt; LoginWindow();
    login.Show();
    &lt;SPAN class=rem&gt;//The LoginWindow only closes if Authentication succeeds&lt;/SPAN&gt;
    login.Closing += (s, eArgs) =&amp;gt;
    {
       &lt;SPAN class=rem&gt;/*If auth succeeds,hide the button*/&lt;/SPAN&gt;
       btnLogin.Visibility = Visibility.Collapsed;
    };
  }&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;A href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_6.png" mce_href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_6.png"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title=image border=0 alt=image src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_2.png" width=582 height=429 mce_src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Usi.NETDataServicesSilverlightclientlibr_9C79/image_thumb_2.png"&gt;&lt;/A&gt; &lt;BR&gt;The LoginWindow’s “Login” button uses the application wide FormsAuthenticationAdapter instance, discussed above, to login the user. &lt;/P&gt;&lt;PRE class=csharpcode&gt;&lt;SPAN class=kwrd&gt;private&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginUser(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, RoutedEventArgs e)
{
App.FormsAuthAdapter.LoginAsync(txtUserName.Text, txtPassword.Password,
    (loginEventArgs) =&amp;gt;
    {
&lt;SPAN class=kwrd&gt;      if&lt;/SPAN&gt; (loginEventArgs.Result)
       {
         &lt;SPAN class=rem&gt;/*Login succeeded*/&lt;/SPAN&gt;
         &lt;SPAN class=kwrd&gt;this&lt;/SPAN&gt;.DialogResult = &lt;SPAN class=kwrd&gt;true&lt;/SPAN&gt;;
       }
&lt;SPAN class=kwrd&gt;       else&lt;/SPAN&gt;
      {
         &lt;SPAN class=rem&gt;/*Login failed*/&lt;/SPAN&gt;
      }
    }
    );
}
The LoginAsync method’s signature &lt;SPAN class=kwrd&gt;is&lt;/SPAN&gt;:
  &lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// Logs in the User and calls the LoginComplete handler&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="userName"&amp;gt;UserName to login &amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="passWord"&amp;gt;password for the user account&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=rem&gt;/// &amp;lt;param name="pLoginComplete"&amp;gt;Called when the login process is complete&amp;lt;/param&amp;gt;&lt;/SPAN&gt;
&lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; LoginAsync(&lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; userName, &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; passWord, Action&amp;lt;LoginCompletedEventArgs&amp;gt; pLoginComplete)&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	BACKGROUND-COLOR: #ffffff; FONT-FAMILY: consolas, "Courier New", courier, monospace; COLOR: black; FONT-SIZE: small
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	BACKGROUND-COLOR: #f4f4f4; MARGIN: 0em; WIDTH: 100%
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;P&gt;&lt;BR&gt;&lt;BR&gt;Once the user types in his/her username and password and hits “Login” , the Login window hits the WCF authentication service &lt;BR&gt;and extracts the FormsAuth cookie from the response.When the client library makes a request to the Data Service , the FormsAuthenticationAdapter &lt;BR&gt;injects the FormsAuth cookie &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Common errors:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;1. You receive an ArgumentException when trying to set the cookie header in the SendingRequest event.&lt;/P&gt;
&lt;P&gt;a. System.ArgumentException occurred &lt;BR&gt;&amp;nbsp; Message="The 'Cookie' header cannot be modified directly.\r\nParameter name: name" &lt;BR&gt;&amp;nbsp; StackTrace: &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.Net.WebHeaderCollection.ThrowOnRestrictedHeader(String name, String value) &lt;BR&gt;&amp;nbsp; InnerException: &lt;/P&gt;
&lt;P&gt;&lt;B&gt;Resolution: &lt;/B&gt;The reason you get this is because the client library is using the classic networking stack (based on XmlHttpRequest) &lt;BR&gt;to make the request. In this case, the Cookie header isn’t accessible and the above exception is valid. &lt;BR&gt;This is probably the only case where we would ask you to set the HttpStack property on the Client library. &lt;BR&gt;To fix this: &lt;BR&gt;//Set the HttpStack on the client Context instance to force the client library &lt;/P&gt;
&lt;P&gt;//to use the ClientHttpWebRequest stack for network access &lt;BR&gt;publicationContext.HttpStack = HttpStack.ClientHttp;&lt;B&gt; &lt;BR&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Additional resources:&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;B&gt;How do I authenticate my users against the Active Directory from my Silverlight application? &lt;BR&gt;&lt;/B&gt;In ASP.NET Forms Authentication, the Membership provider is responsible for accessing the Credential store and validating the user name and password. &lt;BR&gt;By setting the Membership provider to be the ActiveDirectoryMembershipProvider , you can authenticate the user name and password the user enters &lt;BR&gt;with the credentials stored in Active Directory. For more details , please refer to this MSDN article :&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms998347.aspx#paght000022_usingtheactivedirectorymembershipprovider" mce_href="http://msdn.microsoft.com/en-us/library/ms998347.aspx#paght000022_usingtheactivedirectorymembershipprovider"&gt;Using the ActiveDirectoryMembershipProvider&lt;/A&gt; &lt;BR&gt;&lt;B&gt;References :&lt;/B&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd470115(VS.95).aspx"&gt;About ClientAccessPolicy.xml files&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb547119.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb547119.aspx"&gt;ASP.NET Application Services.&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/aa480476.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa480476.aspx"&gt;ASP.NET Forms Authentication&lt;/A&gt; &lt;BR&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/sx3h274z.aspx" mce_href="http://msdn.microsoft.com/en-us/library/sx3h274z.aspx"&gt;Membership Providers&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9893382" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/phaniraj/attachment/9893382.ashx" length="3537053" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Forms+Authentication/default.aspx">Forms Authentication</category></item><item><title>Using the PHP Toolkit with ADO.NET Data Services</title><link>http://blogs.msdn.com/phaniraj/archive/2009/09/08/using-the-php-toolkit-with-ado-net-data-services.aspx</link><pubDate>Wed, 09 Sep 2009 01:17:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9892837</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9892837.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9892837</wfw:commentRss><description>&lt;ol&gt;   &lt;li&gt;&lt;a href="#Step1"&gt;Setup PHP on your windows machine&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#Step2"&gt;Setup the PHP Toolkit &lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="#Step3"&gt;Setting up the PHP samples on IIS&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#Step4"&gt;Running the sample ADO.NET Data Services&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="#Step5"&gt;PHP Sample Applications Walkthrough&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt; &lt;a name="Step1"&gt;   &lt;h3&gt;Setup PHP on your windows machine&lt;/h3&gt; &lt;/a&gt;  &lt;p&gt;The following steps show you how to setup your windows machine to host PHP applications.    &lt;br /&gt;We will be talking about hosting the only supported ( by MS Support ) PHP CGI application on IIS .&lt;/p&gt;  &lt;p&gt;&lt;a href="http://learn.iis.net/page.aspx/246/using-fastcgi-to-host-php-applications-on-iis-70/"&gt;Using FastCGI to Host PHP Applications on IIS 7.0&lt;/a&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;If you don’t find the &lt;strong&gt;php.ini-recommended &lt;/strong&gt;file , then rename the &lt;strong&gt;php.ini-development &lt;/strong&gt;file from your PHP folder. &lt;/li&gt;    &lt;li&gt;Once you are setup , if you get a HTTP 500 internal server error when browsing to the Php.ini file ,      &lt;br /&gt;then you need setup your timezone in the PHP.ini file . &lt;/li&gt;    &lt;li&gt;To do this , find the line in the php.ini file “date.timezone” . &lt;/li&gt;    &lt;li&gt;If it has a semi-colon before it , remove it . &lt;/li&gt;    &lt;li&gt;Set the date.timezone’s&amp;#160; value to be a valid value from this list : &lt;a href="http://nl3.php.net/manual/en/timezones.php"&gt;List of Supported Timezones&lt;/a&gt; &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;In my php.ini , I have set the value to be &lt;strong&gt;date.timezone = &amp;quot;America/Los_Angeles&amp;quot;&lt;/strong&gt;&lt;/p&gt; &lt;a name="Step2"&gt;   &lt;h3&gt;Setup the PHP Toolkit&lt;/h3&gt; &lt;/a&gt;  &lt;p&gt;Follow the instructions on the codeplex site to setup your machine.    &lt;br /&gt;&lt;a href="http://phpdataservices.codeplex.com/Wiki/View.aspx?title=InstallationGuide"&gt;Installation and Configuration&lt;/a&gt;&lt;/p&gt; &lt;a name="Step3"&gt;   &lt;h3&gt;Setting up the PHP samples on IIS &lt;/h3&gt; &lt;/a&gt;  &lt;p&gt;I have copied the phpsamples folder from the downloaded phpdataservices1.0 folder    &lt;br /&gt;into the %SystemDrive%\inetpub\wwwroot folder.This is just so that I dont need to configure any permissions     &lt;br /&gt;for the IIS accounts.     &lt;br /&gt;Open the IIS manager by running “INETMGR” from the “run” prompt on the start menu&lt;/p&gt;  &lt;p&gt;Select the PHPSamples folder from the “Default Web Site”    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_Not_Application_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Samples_Not_Application" border="0" alt="Samples_Not_Application" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_Not_Application_thumb_1.png" width="146" height="154" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Right-Click the Virtual directory and select “Convert to Application”    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_To_Application.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Samples_To_Application" border="0" alt="Samples_To_Application" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_To_Application_thumb.png" width="204" height="240" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Confirm creating the virtual directory by&amp;#160; pressing “OK” in the next dialog that turns up    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_To_Application_Confirm.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Samples_To_Application_Confirm" border="0" alt="Samples_To_Application_Confirm" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Samples_To_Application_Confirm_thumb.png" width="380" height="263" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;This sets up the PHP applications that access the ADO.NET Data Service,    &lt;br /&gt;We still need to setup the actual Data Services that the PHP Samples access.&lt;/p&gt; &lt;a name="Step4"&gt;   &lt;h3&gt;Running the sample&amp;#160; ADO.NET Data Services&lt;/h3&gt; &lt;/a&gt;  &lt;p&gt;Find the ADODotNetDataServices folder in the PHPDataServices1.0 download.    &lt;br /&gt;This should be under the “samples” directory.     &lt;br /&gt;i.e PHPDataServices1.0\samples\ADODotNetDataServices     &lt;br /&gt;&lt;/p&gt;  &lt;h2&gt;Setup the Databases required for the project to run &lt;/h2&gt;  &lt;p&gt;1) Unzip the zipped database files from the &lt;/p&gt; PHPDataServices1.0\samples\ADODotNetDataServices\data folder.   &lt;br /&gt;2)&amp;#160;&amp;#160; Open up SQL management studio and Connect to your Database server   &lt;br /&gt;3) Right–click the databases node and select “Attach…”   &lt;br /&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Attach_DB_Step_1_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Attach_DB_Step_1" border="0" alt="Attach_DB_Step_1" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Attach_DB_Step_1_thumb.png" width="240" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;4) In the “Attach Database” dialog , press “Add” and select the unzipped “VideoGameStore_Data.mdf” file.    &lt;br /&gt;You will notice that once you select the MDF file&amp;#160; , the dialog will complain about a missing .ldf file.     &lt;br /&gt;5) This is a routine warning , select the ldf file row in the dialog and press “Remove”     &lt;br /&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Attach_DB_Step_2_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Attach_DB_Step_2" border="0" alt="Attach_DB_Step_2" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Attach_DB_Step_2_thumb_1.png" width="480" height="352" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;For the other database Northwind, you can use the sample database that are available from Download.Microsoft.com    &lt;br /&gt;Here’s a link to download the Northwind sample database : &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en"&gt;Northwind and pubs Sample Databases for SQL Server 2000&lt;/a&gt;     &lt;br /&gt;Installation should be straight-forward as it comes with an MSI that is supposed to setup the database for you.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Disclaimer : I already had a copy of the Northwind database on my machine and didn’t use the installer above.      &lt;br /&gt;&lt;/strong&gt;&amp;#160; &lt;br /&gt;Once you have your databases setup , modify the respective connection strings web.config file from the ADODotNetDataServices project.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;NorthwindEntities&lt;/span&gt;&amp;quot; &lt;br /&gt;         &lt;span style="color: red"&gt;connectionString&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;metadata=res://*/NorthwindModel.csdl|res://*/NorthwindModel.ssdl|res://*/NorthwindModel.msl;&lt;br /&gt;                           provider=System.Data.SqlClient;&lt;br /&gt;                           provider connection string=&lt;/span&gt;&lt;span style="color: red"&gt;&amp;amp;quot;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;strong&gt;YOURCONNECTIONSTRINGHERE&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&amp;amp;quot;&lt;/span&gt;&amp;quot; &lt;br /&gt;         &lt;span style="color: red"&gt;providerName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;System.Data.EntityClient&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add &lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;VideoGameStoreEntities&lt;/span&gt;&amp;quot; &lt;br /&gt;         &lt;span style="color: red"&gt;connectionString&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;metadata=res://*/VideoGameStoreModel.csdl|res://*/VideoGameStoreModel.ssdl|res://*/VideoGameStoreModel.msl;&lt;br /&gt;                           provider=System.Data.SqlClient;&lt;br /&gt;                           provider connection string=&lt;/span&gt;&lt;span style="color: red"&gt;&amp;amp;quot;&lt;strong&gt;YOURCONNECTIONSTRINGHERE&lt;/strong&gt;&lt;/span&gt;&lt;span style="color: red"&gt;&lt;strong&gt;&amp;amp;&lt;/strong&gt;quot;&lt;/span&gt;&amp;quot; &lt;br /&gt;         &lt;span style="color: red"&gt;providerName&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;System.Data.EntityClient&lt;/span&gt;&amp;quot; &lt;span style="color: blue"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;/pre&gt;

&lt;ol&gt;
  &lt;li&gt;Once you have the database and the Data Service setup, then configure the project to only run on the URL that the PHP Samples expect to find the Data Service on. 
    &lt;br /&gt;To do this : 

    &lt;br /&gt;In Visual Studio,Go to the properties of the Project. &lt;/li&gt;

  &lt;li&gt;Click on the “Web” Tab in the left-hand pane. &lt;/li&gt;

  &lt;li&gt;Under the “Servers” section , Select the “Specific Port”&amp;#160; option and enter “8080” for the port number. 
    &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Setup_DataService_Select_Port.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Setup_DataService_Select_Port" border="0" alt="Setup_DataService_Select_Port" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Setup_DataService_Select_Port_thumb.png" width="640" height="205" /&gt;&lt;/a&gt; &lt;/li&gt;

  &lt;li&gt;
    &lt;p&gt;Now, run the project in Visual studio and launch the PHP samples by browsing to the Index.php page 
      &lt;br /&gt;in the PHPSamples virtual directory.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;
&lt;a name="Step5"&gt;
  &lt;h3&gt;PHP Sample Applications Walkthrough&lt;/h3&gt;
&lt;/a&gt;

&lt;p&gt;You should see this as the startup page when you run the PHP Samples 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen1.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP_SAMPles_Screen1" border="0" alt="PHP_SAMPles_Screen1" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen1_thumb.png" width="640" height="415" /&gt;&lt;/a&gt; 

  &lt;br /&gt;&lt;strong&gt;Demo&lt;/strong&gt; tab contents 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen_Samples1.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP_SAMPles_Screen_Samples1" border="0" alt="PHP_SAMPles_Screen_Samples1" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen_Samples1_thumb.png" width="640" height="370" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select the ADO.NET Data Services Editor Sample to see some pure PHP awesomeness 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="PHP_SAMPles_Screen2" border="0" alt="PHP_SAMPles_Screen2" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/PHP_SAMPles_Screen2_thumb.png" width="640" height="209" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Here’s an editor page for the Customers Entity Set: 
  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Customers_Edit_Screen.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Customers_Edit_Screen" border="0" alt="Customers_Edit_Screen" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Customers_Edit_Screen_thumb.png" width="640" height="195" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;See that little text box over there ? 
  &lt;br /&gt;Yeah , it allows me to enter the Astoria URI operators like top , skip , filter to filter the rows bound to the grid below. 

  &lt;br /&gt;&lt;strong&gt;The gird is editable too &lt;/strong&gt;, Clicking on the “Detail” link in the first column of the grid brings up an editor for the customers 

  &lt;br /&gt;entity that was selected. 

  &lt;br /&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Customers_Edit_Screen_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Customers_Edit_Screen_2" border="0" alt="Customers_Edit_Screen_2" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/UsingthePHPToolkitwithAD.NETDataServices_143D1/Customers_Edit_Screen_2_thumb.png" width="640" height="312" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So , there you have it , instructions to setup the samples and some tours of the sample applications. 
  &lt;br /&gt;Since I know next to nothing about PHP , I have a few questions for our PHP-Savvy users.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Which application framework(s) do you use&amp;#160; to build PHP applications? I know about CAKE and ZEND , any others? &lt;/li&gt;

  &lt;li&gt;Do you use a specific Validation framework or do you use the one that came with the&amp;#160; application framework? &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9892837" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Php/default.aspx">Php</category></item><item><title>Silverlight toolkit with ADO.NET Data services , Master-Details with Accordion</title><link>http://blogs.msdn.com/phaniraj/archive/2009/06/10/silverlight-toolkit-with-ado-net-data-services-master-details-with-accordion.aspx</link><pubDate>Wed, 10 Jun 2009 10:41:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9723603</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9723603.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9723603</wfw:commentRss><description>&lt;p&gt;Download the sample Silverlight project here : &lt;/p&gt; &lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;  &lt;p&gt;About the Silverlight toolkit&amp;#160; , &lt;/p&gt;  &lt;p&gt;From their Codeplex page : &lt;a title="http://silverlight.codeplex.com/" href="http://silverlight.codeplex.com/"&gt;http://silverlight.codeplex.com/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;“The Silverlight Toolkit is a collection of Silverlight controls, components and utilities made available outside the normal Silverlight release cycle”&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;In the first of a series I am planning , we will talk about how to achieve a Master-Child display using the Accordion control&amp;#160; &lt;br /&gt;from the Silverlight Toolkit control.&lt;/p&gt;  &lt;p&gt;The data model we will be binding looks like this :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLToolkitAccordion_DataModel.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SLToolkitAccordion_DataModel" border="0" alt="SLToolkitAccordion_DataModel" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLToolkitAccordion_DataModel_thumb.png" width="547" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Type Employee has a property called Department of type Department.    &lt;br /&gt;Type Department has a collection of type Employee called Employees.&lt;/p&gt;  &lt;p&gt;Employee and Department are related 1..1    &lt;br /&gt;Department and Employee are related 1..M&lt;/p&gt;  &lt;p&gt;We want to bind the Department names to the header of the Accordion and    &lt;br /&gt;the employees as a list inside the content of the accordion.     &lt;br /&gt;When we are done , the final output should look like this :&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLTOolkit_Accordionoutput.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="SLTOolkit_Accordionoutput" border="0" alt="SLTOolkit_Accordionoutput" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/Silverlighttoolk.NETDataservicesTreeView_10E57/SLTOolkit_Accordionoutput_thumb.png" width="464" height="115" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Configuring the header to show the DepartmentName&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;The Header template of the Accordion has a textblock which binds to the DepartMentName property of the    &lt;br /&gt;Department entity.     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
       &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
       &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
 &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Configuring the content to show the names of the employees working in the department.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The content of the Accordion pane would be a list box which is bound to the Employees collection of the Department 
  &lt;br /&gt;entity type and shows the EmployeeName as the DisplayMember. 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
          &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
          &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
      &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;To write the Silverlight client code for this project ,we will need to generate the Client classes with Databinding enabled. 
  &lt;br /&gt;As shown in &lt;a href="http://blogs.msdn.com/astoriateam/archive/2009/03/21/ado-net-data-services-v1-5-ctp1-data-binding-overview.aspx"&gt;this article&lt;/a&gt; on our team blog .&lt;/p&gt;

&lt;p&gt;Once this is done , we have two ways of binding the accordion , 
  &lt;br /&gt;Eager Loading : Download the employees for a department when you download the departments 

  &lt;br /&gt;Lazy Load : Download the employees for a department when the header of an accordion pane , i.e Department is clicked.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Eager Loading :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt; deptQueryWithEmployees = context.Departments.Expand(&lt;span style="color: #a31515"&gt;&amp;quot;Employees&amp;quot;&lt;/span&gt;) &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt;;&lt;br /&gt;deptQueryWithEmployees.QueryAndBind(acDepartments);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Since the query part itself isnt interesting in the context of this blog post , I’ve abstracted away the querying into an extension method ( QueryAndBind ) and will be available as part of the download. 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Here , as you can see , we are eager loading the Employees for the departments . 
  &lt;br /&gt;I feel that this is wasteful if you have a large number of departments as this not only increases the amount of data on the wire , but it also means that all the data that comes down the wire will be useful .&lt;/p&gt;

&lt;p&gt;For example, if you have about 15 departments and a user may click on 5 or less departments , then downloading employees for all the 15 departments seems inefficient. 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Xaml for Eager Loading&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;acDepartments&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;Width&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;400&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;Lazy Loading : 
    &lt;br /&gt;&lt;/strong&gt;In this case , we will only bind the Headers and&amp;#160; will bind the Employees only if the header is clicked for that department. In the Silverlight Accordion control , the event SelectionChanged is fired when the header of an Accordion Pane is clicked. 

  &lt;br /&gt;By listening to this event , we can find out which department was clicked and load the Employees for that department using BeginLoadProperty . 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;public &lt;/span&gt;DelayLoad() {
           InitializeComponent();
           context = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;TreeViewDataProvider&lt;/span&gt;(&lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Uri&lt;/span&gt;(&lt;span style="color: #a31515"&gt;&amp;quot;TreeViewDataService.svc&amp;quot;&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;UriKind&lt;/span&gt;.RelativeOrAbsolute));
           LoadDepartments();
}
&lt;span style="color: blue"&gt;private void &lt;/span&gt;LoadDepartments(){
    ((&lt;span style="color: #2b91af"&gt;DataServiceQuery&lt;/span&gt;&amp;lt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;&amp;gt;)context.Departments).QueryAndBind(acDepartments);
}&lt;/pre&gt;
We will subscribe to the SelectionChanged event of the Accordion and add “LoadEmployeesForDepartment” as the event handler. 

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;private void &lt;/span&gt;LoadEmployeesForDepartment(&lt;span style="color: blue"&gt;object &lt;/span&gt;sender, &lt;span style="color: #2b91af"&gt;SelectionChangedEventArgs &lt;/span&gt;e)
        {
            &lt;span style="color: green"&gt;//The sender is the control that raised the event
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Accordion &lt;/span&gt;acControl = sender &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Accordion&lt;/span&gt;;
            &lt;span style="color: green"&gt;//Get the Selected Department
            &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Department &lt;/span&gt;selectedDepartment = acControl.SelectedItem &lt;span style="color: blue"&gt;as &lt;/span&gt;&lt;span style="color: #2b91af"&gt;Department&lt;/span&gt;;
            &lt;span style="color: blue"&gt;if &lt;/span&gt;(
                &lt;span style="color: green"&gt;//If the Selected object is department
                &lt;/span&gt;selectedDepartment != &lt;span style="color: blue"&gt;null 
                &lt;/span&gt;&amp;amp;&amp;amp; (
                &lt;span style="color: green"&gt;// If the Employees collection is null or empty
                &lt;/span&gt;selectedDepartment.Employees == &lt;span style="color: blue"&gt;null &lt;/span&gt;|| selectedDepartment.Employees.Count == 0)
                )
            {
                &lt;span style="color: green"&gt;//Call load property , which updates the Employees collection of this instance 
                //and the UI automatically updates itself, since Department type implements INotifyPropertyChanged
                &lt;/span&gt;context.LoadPropertyAndCall&amp;lt;&lt;span style="color: #2b91af"&gt;Employee&lt;/span&gt;&amp;gt;(selectedDepartment, &lt;span style="color: #a31515"&gt;&amp;quot;Employees&amp;quot;&lt;/span&gt;,
                    &lt;span style="color: blue"&gt;null&lt;/span&gt;);
            }

        }&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;&lt;strong&gt;XAML for Delay Load :&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion &lt;/span&gt;&lt;span style="color: red"&gt;x&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: red"&gt;Name&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;acDepartments&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;SelectionChanged&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;LoadEmployeesForDepartment&amp;quot;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate &lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock &lt;/span&gt;&lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Path&lt;/span&gt;&lt;span style="color: blue"&gt;=DepartMentName}&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;TextBlock&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.HeaderTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
            &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox &lt;/span&gt;&lt;span style="color: red"&gt;ItemsSource&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;{&lt;/span&gt;&lt;span style="color: #a31515"&gt;Binding &lt;/span&gt;&lt;span style="color: red"&gt;Employees&lt;/span&gt;&lt;span style="color: blue"&gt;}&amp;quot; &lt;/span&gt;&lt;span style="color: red"&gt;DisplayMemberPath&lt;/span&gt;&lt;span style="color: blue"&gt;=&amp;quot;EmployeeName&amp;quot;&amp;gt;
            &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;ListBox&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
        &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;DataTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
    &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion.ContentTemplate&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;layoutToolkit&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Accordion&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Download the sample Silverlight project here : &lt;/p&gt;
&lt;iframe style="border-bottom: #dde5e9 1px solid; border-left: #dde5e9 1px solid; padding-bottom: 0px; background-color: #ffffff; margin: 3px; padding-left: 0px; width: 240px; padding-right: 0px; height: 26px; border-top: #dde5e9 1px solid; border-right: #dde5e9 1px solid; padding-top: 0px" marginheight="0" src="http://cid-925c2d2bb2d03c6b.skydrive.live.com/embedrow.aspx/SLToolkitAstoria/SLToolkitWithAstoria.zip" frameborder="0" marginwidth="0" scrolling="no"&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;strong&gt;Running the sample app &lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set SLToolkitWithAstoriaWeb as the Start-up project. &lt;/li&gt;

  &lt;li&gt;Set SLToolkitWithAstoriaTestPage.html as the start-up page. &lt;/li&gt;

  &lt;li&gt;To run the EagerLoading sample , just hit F5 &lt;/li&gt;

  &lt;li&gt;To run the DelayLoad sample , follow a-c and add the Query string ?delayLoad to the address bar in the browser that comes up. &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9723603" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Silverlight/default.aspx">Silverlight</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Set Based Operations in Ado.net Data Services Part II</title><link>http://blogs.msdn.com/phaniraj/archive/2009/05/27/set-based-operations-in-ado-net-data-services-part-ii.aspx</link><pubDate>Wed, 27 May 2009 08:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9643661</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9643661.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9643661</wfw:commentRss><description>&lt;P&gt;As an extension to the last blog post dealing with &lt;A href="http://blogs.msdn.com/phaniraj/archive/2008/07/17/set-based-operations-in-ado-net-data-services.aspx" mce_href="http://blogs.msdn.com/phaniraj/archive/2008/07/17/set-based-operations-in-ado-net-data-services.aspx"&gt;Set based filter operations in our client library&lt;/A&gt; ,&lt;BR&gt;we will introduce support for the specifying method calls in the filter expression.&lt;/P&gt;&lt;B&gt;What does this achieve ?&lt;/B&gt;&lt;BR&gt;Currently , the IsIn operator only supports an equality comparision. &lt;BR&gt;With support for Method Calls , you can now select entities in a set which when passed to a method , evaluate true. ex: You can generate Uris such as this : &lt;BR&gt;
&lt;OL&gt;
&lt;LI&gt;/northwind.svc/Customers?$filter = substringof('London',City) or substringof('Berlin',City) or substringof('Prague',City) 
&lt;LI&gt;/northwind.svc/Customers?$filter = startswith('London',City) or startswith('Berlin',City) or startswith('Prague',City) 
&lt;LI&gt;/northwind.svc/Customers?$filter = endswith('London',City) or endswith('Berlin',City) or endswith('Prague',City) &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Fortunately , not a lot of code change is required to get this support.&lt;/P&gt;
&lt;P&gt;We will change the first parameter of the extension method from &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;TEntity, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt;&amp;gt; propertyExpression&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;to &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;TEntity, TValue, &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;&amp;gt; comparisionInvokeExpression&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;which means that where we were initially sending an expression that selects a property of the entity , we now send the Extension method a delegate that accepts the entity and the value being compared against it and returns a boolean value after comparison using a method.&lt;/P&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;example : &lt;BR&gt;&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;T, &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt;&amp;gt;&amp;gt; propertyExpression &lt;STRONG&gt;&lt;EM&gt;means&lt;/EM&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE class=code&gt;customer =&amp;gt; customer.City&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Func&lt;/SPAN&gt;&amp;lt;TEntity, TValue, &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt;&amp;gt;&amp;gt; comparisionInvokeExpression &lt;STRONG&gt;&lt;EM&gt;means&lt;/EM&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;PRE class=code&gt;(cust, cityName) =&amp;gt; cust.City.ToLower().StartsWith(cityName)&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The second change is in the location where we build the comparision expression for values in the set. &lt;BR&gt;we change the line which does the comparision using Expression.Equal with a method call to the comparision expression passed in . &lt;BR&gt;We will change&amp;nbsp; :&lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;//Build a comparision expression which equats the Id of the ENtity with this value in the IDs list
// ex : e.Id == 1
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression &lt;/SPAN&gt;comparison = &lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;.Equal(left, &lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;.Constant(id));&lt;/PRE&gt;to : &lt;BR&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;//The Left Hand Side of the Filter Expression
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MethodCallExpression &lt;/SPAN&gt;comaprisionMethod = comparisionInvokeExpression.Body &lt;SPAN style="COLOR: blue"&gt;as &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MethodCallExpression&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: green"&gt;//Build a comparision expression which calls the method that does the comparision for us
//ex : c=&amp;gt; c.City.Contains(id)
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Expression &lt;/SPAN&gt;comparison = &lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;.Call(
                        comaprisionMethod.Object,
                        comaprisionMethod.Method,
                        &lt;SPAN style="COLOR: #2b91af"&gt;Expression&lt;/SPAN&gt;.Constant(id) );&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The complete code sample is here : &lt;BR&gt;
&lt;SCRIPT src="http://gist.github.com/117227.js" mce_src="http://gist.github.com/117227.js"&gt;&lt;/SCRIPT&gt;
&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9643661" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Linq/default.aspx">Linq</category></item><item><title>Batching Queries using the ADO.NET Data Services CLient library</title><link>http://blogs.msdn.com/phaniraj/archive/2009/03/15/batching-queries-using-the-ado-net-data-services-client-library.aspx</link><pubDate>Mon, 16 Mar 2009 00:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9479899</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9479899.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9479899</wfw:commentRss><description>&lt;P&gt;Did you know you could execute batch queries using the Data Services client library ?&lt;/P&gt;
&lt;P&gt;The API is ExecuteBatch for Synchronous access and Begin/End ExecuteBatch for asynchronous scenarios.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;1) Batching a set of URI Queries .&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;The ExecuteBatch API accepts an array of &lt;A href="http://msdn.microsoft.com/en-us/library/cc646604.aspx" mce_href="http://msdn.microsoft.com/en-us/library/cc646604.aspx"&gt;DataServiceRequest&lt;/A&gt; objects. &lt;BR&gt;Consider this example , you want to batch queries to be sent to the “Products” and “Categories” entity sets of a northwind service.&lt;/P&gt;
&lt;SCRIPT src="http://gist.github.com/113153.js"&gt;&lt;/SCRIPT&gt;

&lt;P&gt;&lt;STRONG&gt;2) Batching Linq Queries&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;If you want to use strongly types Linq queries instead of string based URI queries , you can use the linq support to generate the linq query &lt;/P&gt;
&lt;SCRIPT src="http://gist.github.com/113154.js"&gt;&lt;/SCRIPT&gt;

&lt;P&gt;&lt;STRONG&gt;3) How do I Identify the response if I make duplicate requests with the same ElementType ?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Consider this situation , You make 2 requests both of type DataServiceRequest&amp;lt;Products&amp;gt;&amp;nbsp; , how do you identify &lt;BR&gt;which response is for which request ?&lt;/P&gt;
&lt;P&gt;One of the scenarios&amp;nbsp; I can think of , is that the entity set contains multiple types related via inheritance .&lt;/P&gt;
&lt;P&gt;ex: Customers entity set contains instances of types HappyCustomers and HappierCustomers inheriting from Customers.&lt;/P&gt;
&lt;P&gt;The QueryOperationResponse type contains a &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.services.client.queryoperationresponse.query(VS.95).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.data.services.client.queryoperationresponse.query(VS.95).aspx"&gt;Query&lt;/A&gt; property which returns the DataServiceRequest that this response corresponds to .&lt;/P&gt;
&lt;P&gt;You can pass along the requests you made in the batch as a state to the callback and then compare the Query property of the QueryOperationResponse &lt;BR&gt;to match the response to the request.&lt;/P&gt;
&lt;P&gt;ex: &lt;/P&gt;
&lt;SCRIPT src="http://gist.github.com/113156.js"&gt;&lt;/SCRIPT&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9479899" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Working with Inheritance in Ado.net Data Services</title><link>http://blogs.msdn.com/phaniraj/archive/2008/12/23/working-with-inheritance-in-ado-net-data-services.aspx</link><pubDate>Wed, 24 Dec 2008 01:05:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9250996</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9250996.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9250996</wfw:commentRss><description>&lt;p&gt;I’ve seen this question quite often on the Astoria forums and wanted to write something down so that our users can gain from the discussions that go on in our forums.    &lt;br /&gt;We will discuss how one deals with entities ( tables / records / resources ) that participate in an inheritance hierarchy.     &lt;br /&gt;We shall take the following Data Model to discuss some key scenarios involving the Client Library. &lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;&lt;span class="rem"&gt;//Base Class&lt;/span&gt;
[DataServiceKey(&lt;span class="str"&gt;&amp;quot;PersonID&amp;quot;&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Person {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; PersonID { get; set; }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }
    }

&lt;span class="rem"&gt;//Derived Class&lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Employee : Person {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; EmployeeID { get; set; }
}&lt;/pre&gt;

&lt;p&gt;And you expose an IQueryable&amp;lt;Person&amp;gt; from your data source,&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; InheritedProvider {
        &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;Person&amp;gt; _people;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Initialize()  {
            _people = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Person&amp;gt;(){
                &lt;span class="kwrd"&gt;new&lt;/span&gt; Person  {
                    PersonID =1,
                    Name=&lt;span class="str"&gt;&amp;quot;Phani&amp;quot;&lt;/span&gt;
                },
                &lt;span class="kwrd"&gt;new&lt;/span&gt; Employee {
                    PersonID =2,
                    EmployeeID =3,
                    Name =&lt;span class="str"&gt;&amp;quot;Raj&amp;quot;&lt;/span&gt;
                }
            };
        }
        &lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryable&amp;lt;Person&amp;gt; People {
            get {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (_people == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
                    Initialize();
                &lt;span class="kwrd"&gt;return&lt;/span&gt; _people.AsQueryable&amp;lt;Person&amp;gt;();
            }
        }
    }&lt;/pre&gt;

&lt;p&gt;Browsing to the /People endpoint of the service gives you : &lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot; standalone=&amp;quot;yes&amp;quot; ?&amp;gt; 

  &lt;br /&gt;&amp;lt;feed …Namespace Declarations… &amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;title type=&amp;quot;text&amp;quot;&amp;gt;People&amp;lt;/title&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;id&amp;gt;&lt;a href="http://localhost:13975/Inheritance.svc/People"&gt;http://localhost:13975/Inheritance.svc/People&lt;/a&gt;&amp;lt;/id&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;updated&amp;gt;2008-12-23T20:56:47Z&amp;lt;/updated&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;link rel=&amp;quot;self&amp;quot; title=&amp;quot;People&amp;quot; href=&amp;quot;People&amp;quot; /&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;entry&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;id&amp;gt;&lt;a href="http://localhost:13975/Inheritance.svc/People(1)"&gt;http://localhost:13975/Inheritance.svc/People(1)&lt;/a&gt;&amp;lt;/id&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;title type=&amp;quot;text&amp;quot; /&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;updated&amp;gt;2008-12-23T20:56:47Z&amp;lt;/updated&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;author&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;name /&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/author&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;link rel=&amp;quot;edit&amp;quot; title=&amp;quot;Person&amp;quot; href=&amp;quot;People(1)&amp;quot; /&amp;gt;&amp;#160;&amp;#160; &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;category&lt;/span&gt; &lt;span class="attr"&gt;term&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Repro.Person&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;scheme&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;/pre&gt;

&lt;p&gt;&amp;lt;content type=&amp;quot;application/xml&amp;quot;&amp;gt; 
  &lt;br /&gt;&amp;#160; &amp;lt;m:properties&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;d:PersonID m:type=&amp;quot;Edm.Int32&amp;quot;&amp;gt;1&amp;lt;/d:PersonID&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;d:Name&amp;gt;Phani&amp;lt;/d:Name&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/m:properties&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/content&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/entry&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;entry&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;id&amp;gt;&lt;a href="http://localhost:13975/Inheritance.svc/People(2)"&gt;http://localhost:13975/Inheritance.svc/People(2)&lt;/a&gt;&amp;lt;/id&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;title type=&amp;quot;text&amp;quot; /&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;updated&amp;gt;2008-12-23T20:56:47Z&amp;lt;/updated&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;author&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;name /&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/author&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;link rel=&amp;quot;edit&amp;quot; title=&amp;quot;Person&amp;quot; href=&amp;quot;People(2)&amp;quot; /&amp;gt;&amp;#160; &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;category&lt;/span&gt; &lt;span class="attr"&gt;term&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Repro.Employee&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;scheme&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160; &amp;lt;content type=&amp;quot;application/xml&amp;quot;&amp;gt; 
  &lt;br /&gt;&amp;#160; &amp;lt;m:properties&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;d:PersonID m:type=&amp;quot;Edm.Int32&amp;quot;&amp;gt;2&amp;lt;/d:PersonID&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;d:Name&amp;gt;Raj&amp;lt;/d:Name&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;d:EmployeeID m:type=&amp;quot;Edm.Int32&amp;quot;&amp;gt;3&amp;lt;/d:EmployeeID&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/m:properties&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/content&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/entry&amp;gt; 

  &lt;br /&gt;&amp;#160; &amp;lt;/feed&amp;gt; &lt;/p&gt;

&lt;p&gt;As you can see , the &amp;lt;Category&amp;gt; element of an &amp;lt;entry&amp;gt; element represents the Entity Type that this &amp;lt;entry&amp;gt; represents. 
  &lt;br /&gt;&lt;/p&gt;

&lt;h5&gt;How does this help one with working with against an Entity Set using Inheritance ?&lt;/h5&gt;

&lt;p&gt;Consider the following snippet of Client Code :&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;DataServiceContext dsc = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;URI_TO_DATASERVICE&amp;quot;&lt;/span&gt;));
Employee newEmployee = &lt;span class="kwrd"&gt;new&lt;/span&gt; Employee() {Name = &lt;span class="str"&gt;&amp;quot;Peter Qian&amp;quot;&lt;/span&gt;};
dsc.AddObject(&lt;span class="str"&gt;&amp;quot;People&amp;quot;&lt;/span&gt;, newEmployee);
dsc.SaveChanges();&lt;/pre&gt;
Can you guess what is wrong with this ? 

&lt;br /&gt;

&lt;br /&gt;Yep, since the client library sees that you are trying to insert a Person Entity , we put the Entity Type as “Person” 

&lt;br /&gt;in the payload , i.e , the above operation results in the payload : 

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt; &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;a href="http://schemas.microsoft.com/ado/2007/08/dataservices"&gt;http://schemas.microsoft.com/ado/2007/08/dataservices&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;span class="attr"&gt;       xmlns:m&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;a href="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&lt;/a&gt;&lt;/span&gt; &lt;br /&gt;&lt;span class="attr"&gt;       xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.w3.org/2005/Atom&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;updated&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;2008-12-23T21:23:38.5935141Z&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;updated&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;application/xml&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:EmployeeID&lt;/span&gt; &lt;span class="attr"&gt;m:type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:EmployeeID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Peter Qian&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:PersonID&lt;/span&gt; &lt;span class="attr"&gt;m:type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:PersonID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;br /&gt;

&lt;p&gt;And this causes the Server to respond with : 
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;standalone&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;yes&amp;quot;&lt;/span&gt;?&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;code&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt; &lt;span class="attr"&gt;xml:lang&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;en-US&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Error processing request stream. 
    Type information must be specified for types that take part in inheritance.&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;message&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;error&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This error is because , as you can see in the request payload , the &amp;lt;category&amp;gt; element which specifies the Entity Type is missing form the Request Payload. 
  &lt;br /&gt;Since the Client library doesn’t resolve the Names/Types of the Entities for you , it provides you hooks to customize the name/type resolution 

  &lt;br /&gt;so that the right entity type is specified in the payloads.&lt;/p&gt;

&lt;h5&gt;Why can’t the Client library do this automatically ?&lt;/h5&gt;

&lt;p&gt;Main reason , Since we allow POCO , the type hierarchy of entities on the client can be different compared to the server. 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;In your client code , set the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.resolvename(VS.95).aspx" target="_blank"&gt;ResolveName&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.resolvetype.aspx" target="_blank"&gt;ResolveType&lt;/a&gt; Properties on the&amp;#160; DataServiceContext instance to 

  &lt;br /&gt;override the default type resolution behavior. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;ex :&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;DataServiceContext dsc = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;URI_TO_DATASERVICE&amp;quot;&lt;/span&gt;));
dsc.ResolveName = &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(Type entityType) {
     &lt;span class="kwrd"&gt;return&lt;/span&gt; entityType.FullName.Replace(&lt;span class="str"&gt;&amp;quot;&amp;lt;ClientNamespace&amp;gt;&amp;quot;&lt;/span&gt;, &lt;span class="str"&gt;&amp;quot;&amp;lt;ServerNamespace&amp;gt;&amp;quot;&lt;/span&gt;);
};
dsc.ResolveType = &lt;span class="kwrd"&gt;delegate&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName) {
      &lt;span class="kwrd"&gt;return&lt;/span&gt; Type.GetType(entitySetName);
};
Employee newEmployee = &lt;span class="kwrd"&gt;new&lt;/span&gt; Employee() {Name = &lt;span class="str"&gt;&amp;quot;Peter Qian&amp;quot;&lt;/span&gt;};
dsc.AddObject(&lt;span class="str"&gt;&amp;quot;People&amp;quot;&lt;/span&gt;, newEmployee);
dsc.SaveChanges();&lt;/pre&gt;
Since we provide the right Entity Type Name in the ResolveName property , the right Entity Type 

&lt;br /&gt;is placed in the payload. 

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt; &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices&amp;quot;&lt;/span&gt;            
&lt;span class="attr"&gt;       xmlns:m&lt;/span&gt;&lt;span class="kwrd"&gt;=&lt;a href="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"&gt;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="attr"&gt;       xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.w3.org/2005/Atom&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;category&lt;/span&gt; &lt;span class="attr"&gt;scheme&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/scheme&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;term&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ServerNamespace.Employee&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;updated&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;2008-12-23T21:52:44.8021175Z&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;updated&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;application/xml&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:EmployeeID&lt;/span&gt; &lt;span class="attr"&gt;m:type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:EmployeeID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Peter Qian&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:Name&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;d:PersonID&lt;/span&gt; &lt;span class="attr"&gt;m:type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;d:PersonID&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;br /&gt;Hope this helps . 

&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9250996" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Customizing Serialization of Entities in the ADO.NET Data Services Client Library</title><link>http://blogs.msdn.com/phaniraj/archive/2008/12/11/customizing-serialization-of-entities-in-the-ado-net-data-services-client-library.aspx</link><pubDate>Fri, 12 Dec 2008 02:06:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9199026</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>7</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9199026.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9199026</wfw:commentRss><description>&lt;P&gt;This post is inspired by this forum thread :&lt;A href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/b7a9e01d-c5c2-4478-8f01-00f7f6e0f75f" target=_blank mce_href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataservices/thread/b7a9e01d-c5c2-4478-8f01-00f7f6e0f75f"&gt;Data services client -- exception on saveChanges&lt;/A&gt;&lt;/P&gt;
&lt;H4&gt;Problem Statement &lt;/H4&gt;&lt;BR&gt;
&lt;P&gt;I have added some custom proeprties to the Entity Types Generated by DataSvcUtil.exe /Add Service Reference / Hand Coded , &lt;BR&gt;these properties do not exist on the server and should not be sent to the server . &lt;BR&gt;When I try to save an object of a Type which has custom client-Side only properties to the Data Service using AddObject and SaveChanges, &lt;BR&gt;I get the following error :&lt;/P&gt;&lt;PRE class=csharpcode&gt;Error processing request stream. The property name &lt;SPAN class=str&gt;'{PropertyName}'&lt;/SPAN&gt; specified &lt;SPAN class=kwrd&gt;for&lt;/SPAN&gt; type '{TypeName} &lt;SPAN class=kwrd&gt;is&lt;/SPAN&gt; not valid&lt;/PRE&gt;
&lt;P&gt;This error is basically from the server telling the client library that its sending a payload which does not seem to match the definition &lt;BR&gt;of the Entity Type on the server. &lt;BR&gt;&lt;BR&gt;We can solve this problem by customizing the Payload that the client generates when it sends the entity to the server. &lt;BR&gt;The DataServiceContext exposes an event called &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.writingentity.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.writingentity.aspx"&gt;WritingEntity&lt;/A&gt; that is fired right before we send the payload over the wire.&lt;/P&gt;
&lt;P&gt;Its argumentlist contains &lt;A href="http://msdn.microsoft.com/en-us/library/system.data.services.client.readingwritingentityeventargs.aspx" target=_blank mce_href="http://msdn.microsoft.com/en-us/library/system.data.services.client.readingwritingentityeventargs.aspx"&gt;ReadingWritingEntityEventArgs&lt;/A&gt; which gives you access to the Entity Instance being Serialized ( e.Entity )&amp;nbsp; &lt;BR&gt;and the ATOM Payload (e.Data ) we are about to send to the Server.&lt;/P&gt;
&lt;H5&gt;Removing a property from the ATOM Payload that is being sent to the server.&lt;/H5&gt;&lt;PRE class=darkcsharpcode&gt;&lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; dataContext_WritingEntity(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, ReadingWritingEntityEventArgs e) {

    &lt;SPAN class=rem&gt;// e.Data gives you the XElement for the Serialization of the Entity &lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;//Using XLinq  , you can  add/Remove properties to the element Payload  &lt;/SPAN&gt;
    XName xnEntityProperties = XName.Get(&lt;SPAN class=str&gt;"properties"&lt;/SPAN&gt;, e.Data.GetNamespaceOfPrefix(&lt;SPAN class=str&gt;"m"&lt;/SPAN&gt;).NamespaceName);
    XElement xePayload = e.Data.Descendants().Where&amp;lt;XElement&amp;gt;(xe =&amp;gt; xe.Name == xnEntityProperties).First&amp;lt;XElement&amp;gt;();
   &lt;SPAN class=rem&gt;//The XName of the property we are going to remove from the payload&lt;/SPAN&gt;
    XName xnProperty = XName.Get(“{PropertyName}”, e.Data.GetNamespaceOfPrefix(&lt;SPAN class=str&gt;"d"&lt;/SPAN&gt;).NamespaceName);

    &lt;SPAN class=rem&gt;//Get the Property of the entity  you don't want sent to the server&lt;/SPAN&gt;
    XElement xeRemoveThisProperty = xePayload.Descendants().Where&amp;lt;XElement&amp;gt;(xe =&amp;gt; xe.Name == xnProperty).First&amp;lt;XElement&amp;gt;();
    &lt;SPAN class=rem&gt;//Remove this property from the Payload sent to the server &lt;/SPAN&gt;
     xeRemoveThisProperty.Remove();

     }
}&lt;/PRE&gt;
&lt;P&gt;Generalizing this further , we want to make it easier to customize the serialization of multiple entity types without having to write &lt;BR&gt;multiple copies of the WritingEntity event handler. &lt;BR&gt;We will add an attribute that specfies that a certain CLR property should not be serialized in the ATOM Payload when the client library &lt;BR&gt;sends the entity to the server.&lt;/P&gt;&lt;PRE class=darkcsharpcode&gt;    &lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;/// Properties marked with this Attribute are not serialized in the payload when sent to the server&lt;/SPAN&gt;
    &lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
    [AttributeUsage(AttributeTargets.Property)]
    &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; DoNotSerializeAttribute : Attribute
    {
    }&lt;/PRE&gt;
&lt;P&gt;Now , we change the WritingEntity Event handler to remove any property&amp;nbsp; that has this attribute on it . &lt;BR&gt;&lt;BR&gt;&lt;/P&gt;&lt;PRE class=darkcsharpcode&gt;        &lt;SPAN class=kwrd&gt;void&lt;/SPAN&gt; DataServiceContextEx_WritingEntity(&lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt; sender, ReadingWritingEntityEventArgs e)
        {
            &lt;SPAN class=rem&gt;// e.Data gives you the XElement for the Serialization of the Entity &lt;/SPAN&gt;
            &lt;SPAN class=rem&gt;//Using XLinq  , you can  add/Remove properties to the element Payload  &lt;/SPAN&gt;
            XName xnEntityProperties = XName.Get(&lt;SPAN class=str&gt;"properties"&lt;/SPAN&gt;, e.Data.GetNamespaceOfPrefix(&lt;SPAN class=str&gt;"m"&lt;/SPAN&gt;).NamespaceName);
            XElement xePayload = &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;;
            &lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; (PropertyInfo property &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; e.Entity.GetType().GetProperties())
            {
                &lt;SPAN class=kwrd&gt;object&lt;/SPAN&gt;[] doNotSerializeAttributes = property.GetCustomAttributes(&lt;SPAN class=kwrd&gt;typeof&lt;/SPAN&gt;(DoNotSerializeAttribute), &lt;SPAN class=kwrd&gt;false&lt;/SPAN&gt;);
                &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (doNotSerializeAttributes.Length &amp;gt; 0)
                {
                    &lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; (xePayload == &lt;SPAN class=kwrd&gt;null&lt;/SPAN&gt;)
                    {
                        xePayload = e.Data.Descendants().Where&amp;lt;XElement&amp;gt;(xe =&amp;gt; xe.Name == xnEntityProperties).First&amp;lt;XElement&amp;gt;();
                    }
                    &lt;SPAN class=rem&gt;//The XName of the property we are going to remove from the payload&lt;/SPAN&gt;
                    XName xnProperty = XName.Get(property.Name, e.Data.GetNamespaceOfPrefix(&lt;SPAN class=str&gt;"d"&lt;/SPAN&gt;).NamespaceName);
                    &lt;SPAN class=rem&gt;//Get the Property of the entity  you don't want sent to the server&lt;/SPAN&gt;
                    XElement xeRemoveThisProperty = xePayload.Descendants().Where&amp;lt;XElement&amp;gt;(xe =&amp;gt; xe.Name == xnProperty).First&amp;lt;XElement&amp;gt;();
                    &lt;SPAN class=rem&gt;//Remove this property from the Payload sent to the server &lt;/SPAN&gt;
                    xeRemoveThisProperty.Remove();
                }
            }
        }&lt;/PRE&gt;
&lt;P&gt;We can encapsulate this functionality into its own class and any DataServiceContext type that inherits from this class should be able to &lt;BR&gt;inherit this functionality too . &lt;BR&gt;Complete Source Code :&lt;/P&gt;
&lt;SCRIPT src="http://gist.github.com/113147.js" mce_src="http://gist.github.com/113147.js"&gt;&lt;/SCRIPT&gt;

&lt;H4&gt;Using this in your applications : &lt;/H4&gt;
&lt;P&gt;Create a partial class with the same name as shown above and include it in your application to get this behavior.&lt;/P&gt;
&lt;P&gt;Attribute your types with the DoNotSerializeAttribute&amp;nbsp; attribute so that this property is not serialized. &lt;BR&gt;&lt;/P&gt;&lt;PRE class=darkcsharpcode&gt; &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;class&lt;/SPAN&gt; TestType
    {
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;int&lt;/SPAN&gt; ID { get; set; }
        &lt;SPAN class=rem&gt;/// &amp;lt;summary&amp;gt;&lt;/SPAN&gt;
        &lt;SPAN class=rem&gt;/// This Property is client-only , should not be sent to the server&lt;/SPAN&gt;
        &lt;SPAN class=rem&gt;/// &amp;lt;/summary&amp;gt;&lt;/SPAN&gt;
        [DoNotSerialize]
        &lt;SPAN class=kwrd&gt;public&lt;/SPAN&gt; &lt;SPAN class=kwrd&gt;string&lt;/SPAN&gt; ClientOnlyProperty { get; set; }
    }&lt;/PRE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9199026" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Prototype/default.aspx">Prototype</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Working with associations in ADO.NET Data Services , Part 2</title><link>http://blogs.msdn.com/phaniraj/archive/2008/10/23/working-with-associations-in-ado-net-data-services-part-2.aspx</link><pubDate>Fri, 24 Oct 2008 00:01:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9013687</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>10</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9013687.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9013687</wfw:commentRss><description>&lt;p&gt;In part 2 ,we will talk about how to use the client library to deal with :&lt;/p&gt;  &lt;h1&gt;1..N Associations&lt;/h1&gt;  &lt;p&gt;This is the case of entities associated with each other 1..N . An example from Northwind is the relation between Categories and Products Entities. &lt;/p&gt;  &lt;p&gt;An instance of the Categories entity type should have associated Products entities, this is another way of saying “ A row in the Products table should have links to a row in the Categories table”.    &lt;br /&gt;In case of 1..N relations , the left( child ) ends of the association are expressed as Collection properties on the right ( parent ) end of the relation.     &lt;br /&gt;This is shown in the metadata of the service as :&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Categories&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;&amp;lt;!-- Primary Key--&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyRef&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CategoryID&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
 &lt;span class="rem"&gt;&amp;lt;!--Primitive Properties--&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CategoryID&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CategoryName&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.String&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Description&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.String&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Picture&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Binary&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
 &lt;span class="rem"&gt;&amp;lt;!-- Child Entity Set--&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NavigationProperty&lt;/span&gt; 
        &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Products&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;Relationship&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;northwind.FK_Products_Categories&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;FromRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Categories&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;ToRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Products&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;This leads the client utility( DataSvcUtil.exe ) to generate a type Individual which has instances of types Customer and Contact as Properties.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The generated class on the client looks like this : 
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Categories {
  &lt;span class="kwrd"&gt;public&lt;/span&gt; global::System.Collections.ObjectModel.Collection&amp;lt;Products&amp;gt; Products {
            get {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._Products;
            }
            set {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; ((&lt;span class="kwrd"&gt;value&lt;/span&gt; != &lt;span class="kwrd"&gt;null&lt;/span&gt;))
                {
                    &lt;span class="kwrd"&gt;this&lt;/span&gt;._Products = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
                }
            }
        }
}&lt;/pre&gt;

&lt;p&gt;Now that we have set the stage, lets look at how one would use the client library to interact with the related types.&lt;/p&gt;

&lt;h5&gt;Creating the link between the entities &lt;/h5&gt;

&lt;p&gt;You have new instances of Individual , Contact and Customer and you want to persist the new entities and their relation to the store. &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;DataServiceContext dsc = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;http://ServiceEndpoint&amp;quot;&lt;/span&gt;));
Categories freeProductsCategory = &lt;span class="kwrd"&gt;new&lt;/span&gt; Categories()
{
    CategoryName = &lt;span class="str"&gt;&amp;quot;Free Products&amp;quot;&lt;/span&gt;,
    Description = &lt;span class="str"&gt;&amp;quot;These products are free&amp;quot;&lt;/span&gt;,
};
Products freeHeadPhones = Products.CreateProducts(0, &lt;span class="str"&gt;&amp;quot;Free Headphones&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);
Products freeZune = Products.CreateProducts(1, &lt;span class="str"&gt;&amp;quot;Free Zune&amp;quot;&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);

dsc.AddObject(&lt;span class="str"&gt;&amp;quot;Categories&amp;quot;&lt;/span&gt;, freeProductsCategory);
dsc.AddObject(&lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeHeadPhones);
dsc.AddObject(&lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeZune);&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Now what ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since the entities are created and added to the store can’t I just set the Customer and Contact Property to the Individual object and that will save the relation ? 
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;freeProductsCategory.Products.Add(freeHeadPhones);
freeProductsCategory.Products.Add(freeZune);
dsc.SaveChanges();&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Shouldn’t this be enough ? 
  &lt;br /&gt;Nope , that’s not enough to save the relation to the store. 

  &lt;br /&gt;

  &lt;br /&gt;&lt;strong&gt;Why ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Remember that the client context only gives you POCO access to entities in the store and any new entities that you create. 
  &lt;br /&gt;The Client context &lt;strong&gt;does not track any relations &lt;/strong&gt;unless you &lt;strong&gt;explicitly ask it to do so !&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Neat&amp;#160; , now how do I ask it to do that ? &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You use the AddLink method defined on the context. 
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;dsc.AddLink(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeHeadPhones);
dsc.AddLink(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeZune);&lt;/pre&gt;

&lt;p&gt;The signature and the intent of the SetLink method is lucid , it binds 2 entities into a relation , its kinda like a priest at a wedding, 
  &lt;br /&gt;This is what it looks like .. 

  &lt;br /&gt;

  &lt;br /&gt;AddLink ( Parentinstance ,”ChildPropertyName”,ChildInstance)&lt;/p&gt;

&lt;h5&gt;&lt;strong&gt;Deleting the parent entity&lt;/strong&gt;&lt;/h5&gt;

&lt;p&gt;Deleting the parent entity means that the relations with the child entities are also removed. 
  &lt;br /&gt;Think of this as the argument of “How do I delete an entity that has 1..1 links with other&amp;#160;&amp;#160; entities?” 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if I delete the parent entity without deleting the links ?&lt;/strong&gt;&lt;/p&gt;
It depends on your store . If your database is configured to do a cascade delete on deletion of the parent entity ,you might get away with deleting the entity without removing the links 

&lt;p&gt;The right way to delete the entity is to remove all the links it has with the child entities and then delete the entity itself. 
  &lt;br /&gt;The code would look like this.. 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;DataServiceContext dsc = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceContext(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;http://ServiceEndpoint&amp;quot;&lt;/span&gt;));
&lt;span class="rem"&gt;//Load an existing parent&lt;/span&gt;
Categories freeProductsCategory = dsc&lt;br /&gt;                                  .CreateQuery&amp;lt;Categories&amp;gt;(&lt;span class="str"&gt;&amp;quot;Categories&amp;quot;&lt;/span&gt;)
                                  .Where(cat =&amp;gt; cat.CategoryName == &lt;span class="str"&gt;&amp;quot;Free Products&amp;quot;&lt;/span&gt;)
                                  .First();
&lt;span class="rem"&gt;//Load all the related child Entities&lt;/span&gt;
dsc.LoadProperty(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;);

&lt;span class="rem"&gt;//Delete the links with each of the child entities&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Products freeProduct &lt;span class="kwrd"&gt;in&lt;/span&gt; freeProductsCategory.Products) {
    dsc.DeleteLink(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeProduct);
}
&lt;span class="rem"&gt;//Delete the parent entity&lt;/span&gt;
dsc.DeleteObject(freeProductsCategory);
dsc.SaveChanges();&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Wait !! what’s with the LoadProperty there ? 
    &lt;br /&gt;&lt;/strong&gt;Well, if you need to delete the relation , the way to identify the relation or the link is to have both the right and the left end of the relations to be materialized. without the expand , the Contact and the Customer property are null , and we don’t know which relation to delete.In case of 1..1 relations it might be easy to predict based on the relation name , 

  &lt;br /&gt;but wouldn’t be easy in case of 1..n relations. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Deleting the child entity&lt;/strong&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="rem"&gt;//Load an existing parent&lt;/span&gt;
Categories freeProductsCategory = dsc
                                   .CreateQuery&amp;lt;Categories&amp;gt;(&lt;span class="str"&gt;&amp;quot;Categories&amp;quot;&lt;/span&gt;)
                                   .Where(cat =&amp;gt; cat.CategoryName == &lt;span class="str"&gt;&amp;quot;Free Products&amp;quot;&lt;/span&gt;)
                                   .First();
&lt;span class="rem"&gt;//Load all the related child Entities&lt;/span&gt;
dsc.LoadProperty(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;);

&lt;span class="rem"&gt;//Delete the links with each of the child entities&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (Products freeProduct &lt;span class="kwrd"&gt;in&lt;/span&gt; freeProductsCategory.Products) {
    dsc.DeleteLink(freeProductsCategory, &lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;, freeProduct);
&lt;span class="rem"&gt;    //Delete the child entity&lt;/span&gt;
    dsc.DeleteObject(freeProduct);
}
dsc.SaveChanges();&lt;/pre&gt;

&lt;h5&gt;Special Consideration for Navigation properties that are named differently than the Entity Type&lt;/h5&gt;

&lt;p&gt;This is a special case because of a bug in the client library at the time of writing this post. 
  &lt;br /&gt;If you have a navigation property&amp;#160; which is named differently than the EntityType and try to delete the link between the source 

  &lt;br /&gt;and the navigation property , we produce an invalid URI for the DELETE of the link. 

  &lt;br /&gt;

  &lt;br /&gt;ex: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Entity Type :&lt;/strong&gt; Customers , &lt;strong&gt;EntitySet Name : &lt;/strong&gt;Customers 

  &lt;br /&gt;&lt;strong&gt;Navigation Properties : 
    &lt;br /&gt;&lt;/strong&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;EntityType :&lt;/strong&gt; Orders , &lt;strong&gt;Navigation Property Name :&lt;/strong&gt; CashOrders 

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;strong&gt;EntityType : &lt;/strong&gt;Orders , &lt;strong&gt;Navigation Property Name : &lt;/strong&gt;CreditCardOrders 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;
  &lt;br /&gt;Upon calling , 

  &lt;br /&gt;dataContext.DeleteLink(customerInstance,”CashOrders”,orderInstance); 

  &lt;br /&gt;

  &lt;br /&gt;We generate a DELETE to the URI 

  &lt;br /&gt;/Customers(Key)/$links/Orders(Key) 

  &lt;br /&gt;This is wrong , the DELETE should go to : 

  &lt;br /&gt;/Customers(Key)/$links/CashOrders(Key) 

  &lt;br /&gt;

  &lt;br /&gt;We will address this issue in a future release .In the meantime ,&amp;#160; use the workaround below , &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; YourDataContextClass {

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DeleteLinkManual(&lt;span class="kwrd"&gt;object&lt;/span&gt; source, &lt;span class="kwrd"&gt;string&lt;/span&gt; associationName, &lt;span class="kwrd"&gt;object&lt;/span&gt; target) {
            System.Uri UriOfParent;
            System.Uri UriOfChild;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.TryGetUri(source, &lt;span class="kwrd"&gt;out&lt;/span&gt; UriOfParent);
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.TryGetUri(target, &lt;span class="kwrd"&gt;out&lt;/span&gt; UriOfChild);

            &lt;span class="rem"&gt;//Get the Segment of the URI with the Key &lt;/span&gt;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; strChildAssociationURI = UriOfChild.Segments.Last();
            strChildAssociationURI = strChildAssociationURI.Substring(strChildAssociationURI.IndexOf(&lt;span class="str"&gt;'('&lt;/span&gt;));

            &lt;span class="rem"&gt;//ServiceEndPoint/ParentEntitySet/$links/NavigationPropertyName(ChildEntitySetKey)&lt;/span&gt;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; requestUriForLinkDelete = System.String.Format(&lt;span class="str"&gt;&amp;quot;{0}/{1}/$links/{2}{3}&amp;quot;&lt;/span&gt;,
                                             &lt;span class="kwrd"&gt;this&lt;/span&gt;.BaseUri.OriginalString,
                                             UriOfParent.Segments.Last(),
                                             associationName,
                                             strChildAssociationURI);

            System.Net.WebRequest request = System.Net.WebRequest.Create(requestUriForLinkDelete);
            request.Method = &lt;span class="str"&gt;&amp;quot;DELETE&amp;quot;&lt;/span&gt;;
            System.Net.HttpWebResponse response = request.GetResponse() &lt;span class="kwrd"&gt;as&lt;/span&gt; System.Net.HttpWebResponse;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (response.StatusCode != System.Net.HttpStatusCode.NoContent)
            {
                &lt;span class="kwrd"&gt;throw&lt;/span&gt; (&lt;span class="kwrd"&gt;new&lt;/span&gt; System.Data.Services.Client.DataServiceClientException(&lt;span class="str"&gt;&amp;quot;Delete Failed&amp;quot;&lt;/span&gt;));
            }
            &lt;span class="rem"&gt;//Detach this link as the link no longer exists and keep the context consistent&lt;/span&gt;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.DetachLink(source, associationName, target);
      }
}&lt;/pre&gt;

&lt;p&gt;and then , in your code , &lt;/p&gt;

&lt;br /&gt;

&lt;pre class="darkcsharpcode"&gt;YourDataContext dataContext = new YourDataContext(&amp;lt;Uri&amp;gt;);&lt;br /&gt;dataContext.DeleteLinkManual(customerInstance,”CashOrders”,orderInstance);&lt;/pre&gt;

&lt;p&gt;This will produce the right URI : &lt;/p&gt;

&lt;br /&gt;

&lt;pre class="darkcsharpcode"&gt;ServiceEndPoint/Customers(Key)/$links/CashOrders(Key) &lt;/pre&gt;

&lt;p&gt;Note that this doesnt work in Silverlight , I will create a separate sample for Silverlight later . 
  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;If you have any questions&amp;#160; , leave a comment . If you have any issues with code and need help , please post your query on the astoria forums as I can’t promise that I will be able to reply to emails sent to me directly .The whole team is very active on the forums and the more eyes on a problem the better. &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9013687" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Debugging/default.aspx">Debugging</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Accessing Cross-Domain ADO.NET Data Services from the Silverlight Client Library</title><link>http://blogs.msdn.com/phaniraj/archive/2008/10/21/accessing-cross-domain-ado-net-data-services-from-the-silverlight-client-library.aspx</link><pubDate>Tue, 21 Oct 2008 05:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9008548</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/9008548.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=9008548</wfw:commentRss><description>&lt;p&gt;When we built the client library for Silverlight in Silverlight 2.0 , the underlying Network Stack provided by Silverlight core libraries    &lt;br /&gt;was very limited in terms of the Status Codes and Request Verbs that it supported.Our options were :     &lt;br /&gt;a) Use the System.Net libraries provided by the agClr and give a limited subset of the functionality available on the desktop.     &lt;br /&gt;b) Cook up our own Network stack and provide all the functionality provided on the desktop , in Silverlight.&lt;/p&gt;  &lt;p&gt;We went with Option (b) and built a network stack that uses the browser’s underlying XmlHttpRequest object.    &lt;br /&gt;This means that the &lt;a href="http://msdn.microsoft.com/en-us/library/cc197955(VS.95).aspx"&gt;cross domain access available in Silverlight networking stack&lt;/a&gt; is not available in our networking stack.     &lt;br /&gt;    &lt;br /&gt;Forums user Ben Hayat asked a &lt;a href="http://forums.microsoft.com/Forums/ShowPost.aspx?PostID=3995200&amp;amp;SiteID=1"&gt;question&lt;/a&gt; about the guidelines for Cross-Domain access using our Silverlight Client Library .     &lt;br /&gt;&lt;/p&gt;  &lt;p&gt;Now , this is not supported out of the box . But ,you can use the same solution as you would for an Ajax application ,    &lt;br /&gt;which is building&amp;#160; a server-side proxy that talks to the remote service and is completely transparent to the client library.     &lt;br /&gt;    &lt;br /&gt;Below is a sample Server-Side proxy that would help one talk to Data Services hosted on a different domain than the Silverlight application.     &lt;br /&gt;    &lt;br /&gt;There are a couple of issues that a Server-Side proxy needs to solve for an ADO.NET Data Service ,     &lt;br /&gt;&amp;#160; a) Appear totally transparent     &lt;br /&gt;&amp;#160; b) Resolve Identities of resources to appear as they would from the Proxy service and not the original Data Service.     &lt;br /&gt;    &lt;br /&gt;Issue a) is easy , Issue b) is a little more involved.     &lt;br /&gt;    &lt;br /&gt;When the client library receives a Payload back as part of a query ,we construct the entity’s identity based on the following rules,     &lt;br /&gt;ex: If you browse to &lt;a href="http://ServiceEndpoint/Northwind.svc/"&gt;&lt;strong&gt;http://ServiceEndpoint&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;/Northwind.svc/Customers('ALFKI') ,&lt;/strong&gt;the response looks like this :&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&amp;#160;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt; &lt;strong&gt;&lt;font color="#800040"&gt;&lt;span class="attr"&gt;xml:base&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://ServiceEndpointNorthwind.svc/&amp;quot;&lt;/span&gt; 
&lt;/font&gt;&lt;/strong&gt;       &lt;span class="attr"&gt;xmlns:d&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices&amp;quot;&lt;/span&gt; 
       &lt;span class="attr"&gt;xmlns:m&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://schemas.microsoft.com/ado/2007/08/dataservices/metadata&amp;quot;&lt;/span&gt; 
       &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.w3.org/2005/Atom&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;strong&gt;&lt;font color="#800000"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;edit&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Customers&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Customers('ALFKI')&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;/font&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;http://ServiceEndpointNorthwind.svc/Customers('ALFKI')&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;/strong&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;application/xml&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;strong&gt;Properties go here &lt;br /&gt;&lt;/strong&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;m:properties&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;entry&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;When we get the above payload back as a response , we&amp;#160; create&amp;#160; a Customer object and its identity is the value of the &amp;lt;id&amp;gt; field in the payload. 
  &lt;br /&gt;When you make any edits to this Customer object, &lt;u&gt;the edits are sent to the URI specified in the &amp;lt;link rel=”edit”&amp;gt; value of the payload. 
    &lt;br /&gt;&lt;/u&gt;Which means that the proxy server has to modify the payload it recieves from the real Data Service to make sure that all links , Id and Edit 

  &lt;br /&gt;point to the proxy Data Service and not the real Data Service. The easiest way to do this is to do a String.Replace replacing all occurrences of the 

  &lt;br /&gt;the original Service end point with the Proxy Service end point in the payload.&lt;/p&gt;

&lt;p&gt;Without further stalling&amp;#160; , here is the&amp;#160; &lt;a href="http://blogs.msdn.com/phaniraj/attachment/9008548.ashx"&gt;Proxy Handler&lt;/a&gt;. &lt;/p&gt;

&lt;h5&gt;A couple of words of caution so that I can keep my job, &lt;/h5&gt;

&lt;ol&gt;
  &lt;li&gt;This is only a sample implementation of what a proxy &lt;strong&gt;could&lt;/strong&gt;&lt;em&gt;&lt;/em&gt; look like. &lt;/li&gt;

  &lt;li&gt;Do &lt;strong&gt;NOT&lt;/strong&gt; use this in your production applications. &lt;/li&gt;

  &lt;li&gt;This is &lt;strong&gt;NOT&lt;/strong&gt; an official solution provided by the ADO.NET Data Services team , 

    &lt;br /&gt;this is just me illustrating how to write a proxy. &lt;/li&gt;

  &lt;li&gt;If you download this sample , it means that you understand these rules . &lt;/li&gt;

  &lt;li&gt;For any problems with this sample , leave a comment on my blog , 
    &lt;br /&gt;the ADO.NET Data Services Forums is &lt;strong&gt;NOT &lt;/strong&gt;the right place for any issues with this proxy. &lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;Running the sample&amp;#160; &lt;/h5&gt;

&lt;ol&gt;
  &lt;li&gt;Download the sources from the link above. &lt;/li&gt;

  &lt;li&gt;Open the solution in Visual Studio 2008 and hit F5. &lt;/li&gt;

  &lt;li&gt;You should see the Silverlight application come up and 
    &lt;br /&gt;get the data from the Data Service hosted in a different application. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Cross Domain Proxy is a generic AShx handler which receives the requests from the Client library and forwards them onto the 
  &lt;br /&gt;original Data Service , gets the response , changes the ID and Edit Links and returns the response to the Silverlight Client . &lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Client Sends request to Proxy Handler &lt;/li&gt;

  &lt;li&gt;Proxy Handler sends the request data to the Original Data Service &lt;/li&gt;

  &lt;li&gt;Data Service responds with response &lt;/li&gt;

  &lt;li&gt;Proxy handler reads response and changes the ID and EDIT links in the payload &lt;/li&gt;

  &lt;li&gt;In case of POST , the Proxy Handler changes the response “Location” Header 
    &lt;br /&gt;so that the identity points to the Proxy Handler and not the Data Service. &lt;/li&gt;

  &lt;li&gt;Proxy handler returns the response data to the client . &lt;/li&gt;
&lt;/ol&gt;

&lt;h5&gt;How do I use this in my application ?&lt;/h5&gt;

&lt;br /&gt;

&lt;p&gt;The source available for download contains “CrossDomainHandlerBase” which is the class that contains the functionality required 
  &lt;br /&gt;for recieving requests from clients and forwarding the requests onto the Data Service. &lt;/p&gt;

&lt;h5&gt;Setting up the Server-Side Proxy &lt;/h5&gt;

&lt;br /&gt;

&lt;ol&gt;
  &lt;li&gt;Add a Generic ASHX Handler to the application that contains the Web page hosting the Silverlight application , 
    &lt;ol&gt;
      &lt;li&gt;Right-Click on Project &lt;/li&gt;

      &lt;li&gt;Add –&amp;gt; New Item –&amp;gt; Generic Handler 
        &lt;br /&gt;&amp;#160;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/AccessingCrossDomainDataServicesfromtheS_C375/image_2.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="449" alt="image" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/AccessingCrossDomainDataServicesfromtheS_C375/image_thumb.png" width="644" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; 2. This will create a Generic Handler which implements IHttpHandler.&lt;/p&gt;

&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; 3. Remove the code stubs for IHttpHandler methods and properties . 
  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; 4. Replace IHttpHandler with “CrossDomainHandlerBase”.&amp;#160; &lt;br /&gt;&amp;#160;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    [WebService(Namespace = &lt;span class="str"&gt;&amp;quot;http://tempuri.org/&amp;quot;&lt;/span&gt;)]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; CrossDomainHandler : CrossDomainHandlerBase
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; CrossDomainHandler()
            : &lt;span class="kwrd"&gt;base&lt;/span&gt;()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.DataServiceURI = &lt;span class="str"&gt;&amp;quot;URI FOR THE DATA SERVICE&amp;quot;&lt;/span&gt;;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.ProxyServiceURI = &lt;span class="str"&gt;&amp;quot;URI FOR THE PROXY SERVICE&amp;quot;&lt;/span&gt;;
        }
     }&lt;/pre&gt;

&lt;p&gt;&amp;#160;&amp;#160;&amp;#160; 4.From this point on , for all purposes , the Proxy Handler service IS the Data Service&lt;/p&gt;

&lt;h5&gt;Setting up the Silverlight application for Cross-Domain access&lt;/h5&gt;

&lt;ol&gt;
  &lt;li&gt;Right-Click on “References” in the Project &lt;/li&gt;

  &lt;li&gt;Select &amp;quot;Add Service Reference&amp;quot; &lt;/li&gt;

  &lt;li&gt;In the “Address” field , enter the URI for the proxy service , &lt;/li&gt;

  &lt;li&gt;&lt;a href="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/AccessingCrossDomainDataServicesfromtheS_C375/image_6.png"&gt;&lt;img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="484" alt="image" src="http://blogs.msdn.com/blogfiles/phaniraj/WindowsLiveWriter/AccessingCrossDomainDataServicesfromtheS_C375/image_thumb_2.png" width="519" border="0" /&gt;&lt;/a&gt; 

    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;In case of the sample solution provided, the Provider is called “DataProvider”, hence 
    &lt;br /&gt;the code-gen produces the code with a type “DataProvider” derived from DataServiceContext. &lt;/li&gt;

  &lt;li&gt;When you instantiate the Context in the Silverlight application , always specify the Base URI 
    &lt;br /&gt;as the Proxy Handler’s URI, 

    &lt;br /&gt;

    &lt;pre class="csharpcode"&gt;DataProvider dataProvider = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataProvider(
                &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;RELATIVE URI FOR THE PROXY SERVICE&amp;quot;&lt;/span&gt;, 
                            UriKind.RelativeOrAbsolute)
                  );&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;This is the most important step of all &lt;strong&gt;, Party on !!&lt;/strong&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To do in the near future :&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Convert the Handler to be an IHttpAsyncHandler so that we dont block on waiting for the response from the Data Service &lt;/li&gt;

  &lt;li&gt;Provide better mechanisms for Identity Resolution other than String.Replace . &lt;/li&gt;

  &lt;li&gt;Write a better demo app than something which binds all the parts of my name to a Grid. &lt;/li&gt;

  &lt;li&gt;Your suggestion goes here . &lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9008548" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/phaniraj/attachment/9008548.ashx" length="2976444" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Prototype/default.aspx">Prototype</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/CrossDomain/default.aspx">CrossDomain</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>DataServiceContext , Detect if there are pending changes</title><link>http://blogs.msdn.com/phaniraj/archive/2008/10/03/dataservicecontext-detect-if-there-are-pending-changes.aspx</link><pubDate>Fri, 03 Oct 2008 20:20:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8975736</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8975736.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8975736</wfw:commentRss><description>&lt;strike&gt;&lt;/strike&gt;  &lt;p&gt;Hi ,&lt;/p&gt;  &lt;p&gt;I ran into this interesting scenario in the forums today .    &lt;br /&gt;How does one find out if there are any pending changes in the DataServiceContext that you have to submit to the store ?     &lt;br /&gt;&amp;#160; &lt;br /&gt;This is quite simple actually .     &lt;br /&gt;The DataServiceContext has 2 collections called &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.entities.aspx"&gt;Entities&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.dataservicecontext.links.aspx"&gt;Links&lt;/a&gt;. These collections contain entities and links that are tracked by the context.     &lt;br /&gt;Given these collections , how does one know if any of them were changed on the client by the appropriate API ?     &lt;br /&gt;Lets look at the collections one by one ,     &lt;br /&gt;&amp;#160;&lt;/p&gt;  &lt;h4&gt;Entities&lt;/h4&gt;  &lt;p&gt;DataServiceContext.Entities gives you a List&amp;lt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.entitydescriptor.aspx"&gt;EntityDescriptor&lt;/a&gt;&amp;gt;&amp;#160; , each EntityDescriptor instance contains a &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.descriptor.state.aspx"&gt;State&lt;/a&gt; property.     &lt;br /&gt;If the State is anything other than &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.entitystates.aspx"&gt;Unchanged&lt;/a&gt; , then the changes made to the entity on the client side are not commited to the server.     &lt;br /&gt;This is because we change the states of the entities to Unchanged&amp;#160;&amp;#160; after you call SaveChanges on the context.&lt;/p&gt;  &lt;p&gt;The basic state changes are : &lt;/p&gt;  &lt;p&gt;UpdateObject –&amp;gt; Modified&amp;#160;&amp;#160; -&amp;gt; SaveChanges –&amp;gt; UnChanged    &lt;br /&gt;DeleteObject&amp;#160; –&amp;gt; Deleted&amp;#160;&amp;#160;&amp;#160; -&amp;gt; SaveChanges –&amp;gt; UnChanged     &lt;br /&gt;AddObject&amp;#160;&amp;#160;&amp;#160;&amp;#160; –&amp;gt; Added&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; -&amp;gt; SaveChanges –&amp;gt; UnChanged&lt;/p&gt;  &lt;p&gt;So , to find out if there are any entities&amp;#160; in the DataServiceContext which have been changed and not saved,    &lt;br /&gt;you would write something like this :     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; pendingEntityChanges = dsContext.Entities.Any(ed =&amp;gt; ed.State != EntityStates.Unchanged);&lt;/pre&gt;

&lt;br /&gt;

&lt;h4&gt;Links&lt;/h4&gt;

&lt;p&gt;DataServiceContext.Links gives you a List&amp;lt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.linkdescriptor.aspx"&gt;LinkDescriptor&lt;/a&gt;&amp;gt; , each LinkDescriptor instance contains a &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.services.client.descriptor.state.aspx"&gt;State&lt;/a&gt; property , 

  &lt;br /&gt;&lt;/p&gt;

&lt;h5&gt;Links that point to collection properties&lt;/h5&gt;&amp;#160;&amp;#160;&amp;#160; AddLink-&amp;gt; Added –&amp;gt; SaveChanges –&amp;gt; UnChanged 

&lt;br /&gt;&amp;#160;&amp;#160; DeleteLink –&amp;gt; Deleted –&amp;gt; SaveChanges –&amp;gt; Detached 

&lt;h5&gt;Links that point to reference properties&lt;/h5&gt;

&lt;p&gt;SetLink with Target not Null –&amp;gt; Modified –&amp;gt; SaveChanges –&amp;gt; UnChanged 
  &lt;br /&gt;SetLink with Target Null –&amp;gt; Modified –&amp;gt; SaveChanges –&amp;gt; Detached 

  &lt;br /&gt;

  &lt;br /&gt;To query for links which have not yet been saved , you would write : 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; pendingLinkChanges = dsContext.Links.Any(ld =&amp;gt; ld.State != EntityStates.Unchanged);&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;and finally , the function to check if there are any unsaved changes ( Entities / Links ) in the context : 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; HasUnsavedChanges(DataServiceContext dataContext){
  &lt;span class="rem"&gt;//Check if any Entities are unsaved&lt;/span&gt;
 &lt;span class="kwrd"&gt;return&lt;/span&gt; dataContext.Entities.Any(ed =&amp;gt; ed.State != EntityStates.Unchanged)
 &lt;span class="rem"&gt;//Check if any Links are unsaved&lt;/span&gt;
 || dataContext.Links.Any(ld =&amp;gt; ld.State != EntityStates.Unchanged)
}&lt;/pre&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8975736" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/DataServiceContext/default.aspx">DataServiceContext</category></item><item><title>Ajax preview 2 : Declarative Instantiation of AjaxControlToolkit Controls</title><link>http://blogs.msdn.com/phaniraj/archive/2008/09/12/ajax-preview-2-declarative-instantiation-of-ajaxcontroltoolkit-controls.aspx</link><pubDate>Fri, 12 Sep 2008 09:56:29 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8945964</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8945964.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8945964</wfw:commentRss><description>&lt;p&gt;Today ,we will talk about using the Declarative Syntax to instantiate certain AjaxControlToolkit Behaviors .    &lt;br /&gt;    &lt;br /&gt;Step 0: Figure out which are the script files needed for the Behavior to work and include the appropriate Script&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; references&amp;#160; in your page .     &lt;br /&gt;For the PopupControlBehavior , the script files would be :&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;AjaxControlToolkit.ExtenderBase.BaseScripts.js
AjaxControlToolkit.Common.Common.js
AjaxControlToolkit.Compat.Timer.Timer.js
AjaxControlToolkit.Animation.Animations.js
AjaxControlToolkit.Animation.AnimationBehavior.js
AjaxControlToolkit.PopupExtender.PopupBehavior.js
AjaxControlToolkit.PopupControl.PopupControlBehavior.js&lt;/pre&gt;

&lt;p&gt;Step 1: Declare the behaviors you wish to attach to the templated elements.&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt; &lt;span class="attr"&gt;xmlns:sys&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;javascript:Sys&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;xmlns:popup&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;javascript:AjaxControlToolkit.PopupControlBehavior&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Step 2 : In the template , attach this behavior to the target element using the sys:attach syntax.&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;#&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sys:attach&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;popup&amp;quot;&lt;/span&gt; .....&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Some Text Here&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Step 3 : Depending on the behavior you are using , set the appropriate properties . 
  &lt;br /&gt;Since I am using the PopupControlBehavior , we will need to set the PopupControlID and the Position properties of the behavior.&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;popup:popupcontrolid&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;quot;&lt;/span&gt;  &lt;span class="attr"&gt;popup:position&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;...&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Declarative template&amp;#160; for Master-Details view with popupbehavior : &lt;/strong&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;listTemplate&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;width: 150px&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;yellow&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt; &lt;span class="attr"&gt;sys:attach&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;dataview&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;sys-template&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;dataview:data&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{{ localData }}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;           &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt; &lt;span class="attr"&gt;sys:attach&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;popup&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;popup:popupcontrolid&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{{'subDiv'+ListID}}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;popup:position&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;4&amp;quot;&lt;/span&gt;
      &lt;span class="attr"&gt;sys:id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{{'master'+ ListID}}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;{{ ListTitle }}&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;span&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;
       &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{{ 'subDiv' + ListID}}&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;grey&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;display: none; width: 300px&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;
           &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;sys-template&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;sys:attach&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;dataview&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;dataview:data&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;{{ ListElements }}&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;{{ListElementText}} &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;
           &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;
          &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Complete Sample Code : &lt;a href="http://cid-925c2d2bb2d03c6b.skydrive.live.com/self.aspx/Public/DeclarativeMasterDetails.txt"&gt;Click Me&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8945964" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/asp.net+ajax+4_2E002E00_0/default.aspx">asp.net ajax 4..0</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/AjaxControlToolkit/default.aspx">AjaxControlToolkit</category></item><item><title>Documentation for the AjaxControlToolkit</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/27/documentation-for-the-ajaxcontroltoolkit.aspx</link><pubDate>Wed, 27 Aug 2008 07:07:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8898885</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8898885.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8898885</wfw:commentRss><description>&lt;strike&gt;&lt;/strike&gt;  &lt;p&gt;Ready for some documentation for the ATK controls ?    &lt;br /&gt;To skip my journey to create this , download the Documentation ( in CHM form) here : &lt;a href="http://cid-925c2d2bb2d03c6b.skydrive.live.com/self.aspx/AjaxControlToolkit%20Documentation/AjaxControlToolkit.chm"&gt;AjaxControlToolkit Docs&lt;/a&gt;&lt;/p&gt;  &lt;h5&gt;Step 1 : Using AjaxDoc to generate the Reflection.org file required by Sandcastle&lt;/h5&gt;  &lt;p&gt;&amp;#160;&amp;#160; 1.0) Download AjaxDoc &lt;a href="http://www.codeplex.com/ajaxdoc"&gt;here &lt;/a&gt;.     &lt;br /&gt;&amp;#160;&amp;#160; 1.1) Download the Latest Source for the AjaxControlToolkit , &lt;a href="http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=16488"&gt;here&lt;/a&gt; .&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160; 1.2) Get the Script Files from the AjaxControlToolkit project .     &lt;br /&gt;&amp;#160;&amp;#160; 1.3) Create the AjaxControlToolkit.project.xml for AjaxDoc which has script references to the ATK Scripts.     &lt;br /&gt;&amp;#160;&amp;#160; 1.4) Run the Default.aspx page&lt;/p&gt;  &lt;p&gt;Hurdle 1 : DynamicPopulateBehavior.js just refused to load.&amp;#160; &lt;br /&gt;Added this line to ln 150 of ScriptDoc.js file to skip types which throw errors.     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt;(member ===&lt;span class="kwrd"&gt;null&lt;/span&gt; || &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(member)===&lt;span class="str"&gt;&amp;quot;undefined&amp;quot;&lt;/span&gt;) &lt;span class="kwrd"&gt;continue&lt;/span&gt;; &lt;/pre&gt;

&lt;p&gt;&amp;#160; 1.5) Run the Default.aspx page again 
  &lt;br /&gt;

  &lt;br /&gt;Hurdle 2:&amp;#160; “PopupBehavior is undefined”. 

  &lt;br /&gt;1.6) Re-arranged the script references in the Project.xml file to order the script files according to their dependencies. 

  &lt;br /&gt;1.7) Run the Default.aspx page again . 

  &lt;br /&gt;&lt;/p&gt;

&lt;h5&gt;Step 2 : Use SandCastle to produce the CHM File&lt;/h5&gt;

&lt;p&gt;Follow the Steps 5-12 defined here : &lt;a href="http://blogs.msdn.com/sandcastle/archive/2006/07/29/Creating-a-Chm-build-using-Sandcastle.aspx"&gt;Creating a Chm build using Sandcastle&lt;/a&gt; 

  &lt;br /&gt;Whichever Transform you use (Vs2005/Prototype) , in step 8, remove these lines in the sandcastle.config file.&amp;#160; &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;language&lt;/span&gt; &lt;span class="attr"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;VisualBasic&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;VisualBasic&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;vb&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;language&lt;/span&gt; &lt;span class="attr"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CSharp&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CSharp&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;cs&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;language&lt;/span&gt; &lt;span class="attr"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ManagedCPlusPlus&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ManagedCPlusPlus&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;cpp&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;&amp;lt;!--&amp;lt;language label=&amp;quot;JSharp&amp;quot; name=&amp;quot;JSharp&amp;quot; style=&amp;quot;cs&amp;quot; /&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;&amp;lt;language label=&amp;quot;JScript&amp;quot; name=&amp;quot;JScript&amp;quot; style=&amp;quot;cs&amp;quot; /&amp;gt;--&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;There you go ! &lt;/p&gt;
The CHM is not perfect ,&amp;#160; &lt;ol&gt;
  &lt;li&gt;The documentation is missing for the following components 
    &lt;ol&gt;
      &lt;li&gt;AnimationExtender &lt;/li&gt;

      &lt;li&gt;RichTextEditor &lt;/li&gt;

      &lt;li&gt;MultiHandleSlider &lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;

  &lt;li&gt;The Code Comments are missing from the CHM file &lt;/li&gt;

  &lt;li&gt;Insert gripe here &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I'll probably take a look at this again to see if I can generate a CHM which has the missing parts. 
  &lt;br /&gt;And finally , while Its not everything , its not nothing either :) &lt;/p&gt;
Resources: 

&lt;br /&gt;&lt;a href="http://weblogs.asp.net/bleroy/archive/2007/06/27/scriptdoc-1-0-available.aspx"&gt;Bertrand's blog &lt;/a&gt;

&lt;br /&gt;&lt;a href="http://blogs.msdn.com/sandcastle/archive/2006/07/29/Creating-a-Chm-build-using-Sandcastle.aspx"&gt;SandCastle Blog&lt;/a&gt; 

&lt;br /&gt;&lt;a href="http://www.codeplex.com/ajaxdoc"&gt;AjaxDoc on CodePlex&lt;/a&gt; 

&lt;br /&gt;&lt;a href="http://www.codeplex.com/Sandcastle/"&gt;SandCastle on CodePlex&lt;/a&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8898885" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/AJAX/default.aspx">AJAX</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/JavaScript/default.aspx">JavaScript</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/AjaxControlToolkit/default.aspx">AjaxControlToolkit</category></item><item><title>Entities , How many ways do I count thee ?</title><link>http://blogs.msdn.com/phaniraj/archive/2008/08/18/entities-how-many-ways-do-i-count-thee.aspx</link><pubDate>Mon, 18 Aug 2008 02:51:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8875636</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8875636.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8875636</wfw:commentRss><description>&lt;p&gt;Its a common ask that we introduce aggregating mechanisms in Data services so that one can do a Count of    &lt;br /&gt;the number of entities present in an EntitySet easily.     &lt;br /&gt;In this blog post , I will outline one method of implementing a “Count” method that works for you.     &lt;br /&gt;    &lt;br /&gt;The interface to the count method will be     &lt;br /&gt;&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;http://&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ServiceEndPoint&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;/Count?entitySetName='&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;entitySetName&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;'&lt;/pre&gt;

&lt;h4&gt;Server-Side&lt;/h4&gt;

&lt;p&gt;On the server-side , we will write a Service Operation that takes the name of the EntitySet as an input parameter.&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;[WebGet]
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Count(&lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName) {
 &lt;span class="rem"&gt;//Implementation goes here&lt;/span&gt;
 }&lt;/pre&gt;

&lt;p&gt;In your Service Operations / Interceptors ,&amp;#160; you have access to the CurrentDataSource which represents your data providers. 
  &lt;br /&gt;The entity sets are properties off of the CurrentDataSource. We will get the entityset off of the CurrentDataSource 

  &lt;br /&gt;and get the count of entities by casting it to &lt;a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.ilistsource.aspx"&gt;IListSource&lt;/a&gt;.&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;[WebGet]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Count(&lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName)  {
&lt;span class="kwrd"&gt;&lt;br /&gt;long&lt;/span&gt; countOfEntities = 0;

&lt;span class="rem"&gt;//Get the Property off of the CurrentDataSource&lt;/span&gt;
PropertyInfo esProperty = &lt;span class="kwrd"&gt;this&lt;/span&gt;.CurrentDataSource.GetType().GetProperty(entitySetName);

&lt;span class="rem"&gt;//Get the EntitySet off of the CurrentDataSource&lt;/span&gt;
&lt;span class="kwrd"&gt;object&lt;/span&gt; esValue = esProperty.GetValue(&lt;span class="kwrd"&gt;this&lt;/span&gt;.CurrentDataSource, &lt;span class="kwrd"&gt;null&lt;/span&gt;);

&lt;span class="rem"&gt;//Cast the EntitySet to IListSource&lt;/span&gt;
IListSource genericESList = esValue &lt;span class="kwrd"&gt;as&lt;/span&gt; IListSource;

&lt;span class="rem"&gt;//Get the count of entities by fetching the list and getting the value of its &amp;quot;Count&amp;quot; Property&lt;/span&gt;
countOfEntities = genericESList.GetList().Count;

&lt;span class="kwrd"&gt;return&lt;/span&gt; countOfEntities;
}&lt;/pre&gt;

&lt;h4&gt;Client-Side&lt;/h4&gt;

&lt;p&gt;we will make an extension method on the data service context that takes the name of the entityset and returns the count. 
  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;DataServiceContext nwContext = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceContext( &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(&lt;span class="str"&gt;&amp;quot;ServiceRoot&amp;quot;&lt;/span&gt;) );
&lt;span class="kwrd"&gt;long&lt;/span&gt; countOfProducts = nwContext.Count(&lt;span class="str"&gt;&amp;quot;Products&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;Extension method on the DataServiceContext to retrieve count of entities in entityset&amp;#160; on the server . 
  &lt;br /&gt;

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Count(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataServiceContext context, &lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName) {
 &lt;span class="rem"&gt;//Call the ServiceOperation on the server side passing the entitySetNameas a parameter&lt;/span&gt;
 var results = context.Execute&amp;lt;&lt;span class="kwrd"&gt;long&lt;/span&gt;&amp;gt;(&lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(String.Format(&lt;span class="str"&gt;&amp;quot;Count?entitySetName='{0}'&amp;quot;&lt;/span&gt;, entitySetName),
   UriKind.RelativeOrAbsolute));
 &lt;span class="rem"&gt;//Get the result off of the IEnumerable&lt;/span&gt;
 &lt;span class="kwrd"&gt;long&lt;/span&gt; count = results.First&amp;lt;&lt;span class="kwrd"&gt;long&lt;/span&gt;&amp;gt;();
 &lt;span class="rem"&gt;//return the count&lt;/span&gt;
 &lt;span class="kwrd"&gt;return&lt;/span&gt; count;
}&lt;/pre&gt;

&lt;p&gt;
  &lt;br /&gt;&lt;/p&gt;

&lt;h4&gt;Complete Sample Code : &lt;/h4&gt;

&lt;h5&gt;Put this in your Service Code on the server . &lt;/h5&gt;

&lt;br /&gt;

&lt;pre class="darkcsharpcode"&gt;[WebGet]
[SingleResult]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Count(&lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName) {
&lt;span class="kwrd"&gt;long&lt;/span&gt; countOfEntities = 0;
&lt;span class="kwrd"&gt;if&lt;/span&gt; (entitySetName == &lt;span class="kwrd"&gt;null&lt;/span&gt;) {
  &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;&amp;quot;entitySetName&amp;quot;&lt;/span&gt;);
}
&lt;span class="rem"&gt;//Get the Property off of the CurrentDataSource&lt;/span&gt;
PropertyInfo esProperty = &lt;span class="kwrd"&gt;this&lt;/span&gt;.CurrentDataSource.GetType().GetProperty(entitySetName);
&lt;span class="kwrd"&gt;if&lt;/span&gt; (esProperty == &lt;span class="kwrd"&gt;null&lt;/span&gt;) {
&lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(String.Format(&lt;span class="str"&gt;&amp;quot;No EntitySet named {0} found on the DataSource&amp;quot;&lt;/span&gt;, entitySetName));
}
&lt;span class="kwrd"&gt;try&lt;/span&gt; {
 &lt;span class="rem"&gt;//Get the EntitySet off of the CurrentDataSource&lt;/span&gt;
 &lt;span class="kwrd"&gt;object&lt;/span&gt; esValue = esProperty.GetValue(&lt;span class="kwrd"&gt;this&lt;/span&gt;.CurrentDataSource, &lt;span class="kwrd"&gt;null&lt;/span&gt;);
 &lt;span class="rem"&gt;//Cast the entitySet to IListSource&lt;/span&gt;
 IListSource genericESList = esValue &lt;span class="kwrd"&gt;as&lt;/span&gt; IListSource;
 &lt;span class="rem"&gt;//If the cast succeeded&lt;/span&gt;
 &lt;span class="kwrd"&gt;if&lt;/span&gt; (genericESList != &lt;span class="kwrd"&gt;null&lt;/span&gt;) {
 countOfEntities = genericESList.GetList().Count;
 }
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception exception) {
&lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; DataServiceException(&lt;span class="str"&gt;&amp;quot;'Count' method Failed with , see InnerException --&amp;gt;&amp;quot;&lt;/span&gt;, exception);
}
&lt;span class="kwrd"&gt;return&lt;/span&gt; countOfEntities;
}&lt;/pre&gt;

&lt;h5&gt;Put this in your client Code . &lt;/h5&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ClientExtensions {
&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// This Method returns the count of the number if entities present in an Entityset&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name=&amp;quot;context&amp;quot;&amp;gt;The DataServiceContext which contains the entities&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name=&amp;quot;entitySetName&amp;quot;&amp;gt;The EntitySetName whose entities should be counted&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;The number of entities in the entityset&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;example&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;///  long countOfProducts = context.Count(&amp;quot;Products&amp;quot;);&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/example&amp;gt; &lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;long&lt;/span&gt; Count(&lt;span class="kwrd"&gt;this&lt;/span&gt; DataServiceContext context, &lt;span class="kwrd"&gt;string&lt;/span&gt; entitySetName)
{
    &lt;span class="rem"&gt;//Call the ServiceOperation on the server side passing the entitySetName as a parameter&lt;/span&gt;
    var results = context.Execute&amp;lt;&lt;span class="kwrd"&gt;long&lt;/span&gt;&amp;gt;(&lt;br /&gt;            &lt;span class="kwrd"&gt;new&lt;/span&gt; Uri(String.Format(&lt;span class="str"&gt;&amp;quot;Count?entitySetName='{0}'&amp;quot;&lt;/span&gt;, entitySetName), UriKind.RelativeOrAbsolute)&lt;br /&gt;            );
    &lt;span class="rem"&gt;//Get the result off of the IEnumerable&lt;/span&gt;
    &lt;span class="kwrd"&gt;long&lt;/span&gt; count = results.First&amp;lt;&lt;span class="kwrd"&gt;long&lt;/span&gt;&amp;gt;();
    &lt;span class="rem"&gt;//return the count&lt;/span&gt;
    &lt;span class="kwrd"&gt;return&lt;/span&gt; count;
}
}&lt;/pre&gt;
In a future post , I will talk about how to off load the counting work to your database , if you have a relational database

&lt;br /&gt;as your backend.

&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8875636" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Components/default.aspx">Components</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category></item><item><title>Working with Associations in ADO.NET Data Services</title><link>http://blogs.msdn.com/phaniraj/archive/2008/07/02/working-with-relations-in-ado-net-data-services-beta-1.aspx</link><pubDate>Wed, 02 Jul 2008 08:58:46 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8680242</guid><dc:creator>PhaniRajuYN</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/phaniraj/comments/8680242.aspx</comments><wfw:commentRss>http://blogs.msdn.com/phaniraj/commentrss.aspx?PostID=8680242</wfw:commentRss><description>&lt;p&gt;I’ve seen that users are having some question about how to deal with certain types of relations between entities and how to deal with them in the client library.I will outline the a couple of common scenarios of using the client library among a few relationship types. I'll be using the AdventureWorks Database for examples of relations.&lt;/p&gt;  &lt;h1&gt;1..1 Associations&lt;/h1&gt;  &lt;p&gt;This is the case of entities associated with each other 1..1 . An example from Adventureworks is the relation between Individual and Contact,Customer Entities. &lt;/p&gt;  &lt;p&gt;An instance of the Individual entity type should have associated Contact and Customer entities, this is another way of saying “ A row in the Individual table should have links to a row in the Contact and Customer table”.    &lt;br /&gt;In case of 1..1 relations , the left( child ) ends of the association are expressed as properties on the right ( parent ) end of the relation.This is shown in the metadata of the service as :&lt;/p&gt;  &lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Individual&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PropertyRef&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CustomerID&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Key&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;span class="rem"&gt;&amp;lt;!—Primitive &amp;amp; Complex Properties --&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;CustomerID&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.Int32&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Demographics&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.String&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;MaxLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Max&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Unicode&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;FixedLength&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Property&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;ModifiedDate&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Edm.DateTime&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;Nullable&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;false&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="rem"&gt;&amp;lt;!-- Navigation Properties , Signifying related entities of an association --&amp;gt;&lt;/span&gt;
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NavigationProperty&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Contact&amp;quot;&lt;/span&gt; 
    &lt;span class="attr"&gt;Relationship&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AdventureWorks.FK_Individual_Contact_ContactID&amp;quot;&lt;/span&gt; 
   &lt;span class="attr"&gt;FromRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Individual&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ToRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Contact&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;NavigationProperty&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Customer&amp;quot;&lt;/span&gt;    &lt;span class="attr"&gt;Relationship&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;AdventureWorks.FK_Individual_Customer_CustomerID&amp;quot;&lt;/span&gt; 
   &lt;span class="attr"&gt;FromRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Individual&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;ToRole&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Customer&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;EntityType&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;















.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This leads the client utility( DataSvcUtil.exe ) to generate a type Individual which has instances of types Customer and Contact as Properties.&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;The generated class on the client looks like this :&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Individual {
&lt;span class="rem"&gt;//Other properties removed for brevity &lt;/span&gt;
 &lt;span class="kwrd"&gt;public&lt;/span&gt; Contact Contact {
            get {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._Contact;
            }
            set {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;._Contact = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
&lt;span class="kwrd"&gt;public&lt;/span&gt; Customer Customer {
            get {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;._Customer;
            }
            set {
                &lt;span class="kwrd"&gt;this&lt;/span&gt;._Customer = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
            }
        }
}&lt;/pre&gt;

&lt;p&gt;Trivia : Properties of a type P in an entity type E which signify that the type E has a 1..1 relation with the type P of the property are called as &lt;strong&gt;Reference &lt;/strong&gt;Properties.&lt;/p&gt;

&lt;p&gt;Now that we have set the stage, lets look at how one would use the client library to interact with the related types.&lt;/p&gt;

&lt;h5&gt;Creating the link between the entities &lt;/h5&gt;
You have new instances of Individual , Contact and Customer and you want to persist the new entities and their relation to the store. 

&lt;br /&gt;

&lt;pre class="darkcsharpcode"&gt;Individual individual = &lt;span class="kwrd"&gt;new&lt;/span&gt; Individual();
&lt;span class="rem"&gt;//Initialize all its necessary properties&lt;/span&gt;
Customer newCustomer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer();
&lt;span class="rem"&gt;//Initialize all its necessary properties&lt;/span&gt;
Contact contact = &lt;span class="kwrd"&gt;new&lt;/span&gt; Contact();
&lt;span class="rem"&gt;//Initialize all its necessary properties&lt;/span&gt;

&lt;span class="rem"&gt;//Add the newly created entities to be tracked by the client context&lt;/span&gt;

TestContext.AddObject(&lt;span class="str"&gt;&amp;quot;Individual&amp;quot;&lt;/span&gt;, individual);
TestContext.AddObject(&lt;span class="str"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, newCustomer);  
TestContext.AddObject(&lt;span class="str"&gt;&amp;quot;Contact&amp;quot;&lt;/span&gt;, contact);&lt;/pre&gt;
&lt;style type="text/css"&gt;












.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;Now what ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Since the entities are created and added to the store can’t I just set the Customer and Contact Property to the Individual object and that will save the relation ?&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;individual.Customer = newCustomer;
individual.Contact = contact;
TestContext.SaveChanges();&lt;/pre&gt;
&lt;style type="text/css"&gt;












.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Shouldn’t this be enough ? 
  &lt;br /&gt;Nope , that’s not enough to save the relation to the store. 

  &lt;br /&gt;

  &lt;br /&gt;&lt;strong&gt;Why ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Remember that the client context only gives you POCO access to entities in the store and any new entities that you create.The Client context &lt;strong&gt;does not track any relations &lt;/strong&gt;unless you &lt;strong&gt;explicitly ask it to do so !&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Neat&amp;#160; , now how do I ask it to do that ? &lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beta 1 Code :
    &lt;br /&gt;&lt;/strong&gt;You use the AddLink method defined on the context. &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;TestContext.AddLink(individual, &lt;span class="str"&gt;&amp;quot;Contact&amp;quot;&lt;/span&gt;, contact);
TestContext.AddLink(individual, &lt;span class="str"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, newCustomer);&lt;/pre&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The signature and the intent of the AddLink method is lucid , it binds 2 entities into a relation , its kinda like a priest at a wedding, 
  &lt;br /&gt;“I now bind you into the holy bond of 1..1 relations. You may now change your facebook status“&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;okay , jokes aside , this is what it looks like .. 
  &lt;br /&gt;

  &lt;br /&gt;AddLink ( Parentinstance ,”ChildPropertyName”,ChildInstance)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RTM Code :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You use the SetLink method defined on the context. &lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;TestContext.SetLink(individual, &lt;span class="str"&gt;&amp;quot;Contact&amp;quot;&lt;/span&gt;, contact);
TestContext.SetLink(individual, &lt;span class="str"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, newCustomer);&lt;/pre&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;The signature and the intent of the SetLink method is lucid , it binds 2 entities into a relation , its kinda like a priest at a wedding, 
  &lt;br /&gt;This is what it looks like .. 

  &lt;br /&gt;

  &lt;br /&gt;SetLink ( Parentinstance ,”ChildPropertyName”,ChildInstance)&lt;/p&gt;
&lt;style type="text/css"&gt;











.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;h5&gt;&lt;strong&gt;Deleting the parent entity&lt;/strong&gt;&lt;/h5&gt;

&lt;p&gt;Deleting the parent entity means that the relations with the child entities are also removed. 
  &lt;br /&gt;Think of this as the argument of “How do I delete an entity that has 1..1 links with other&amp;#160;&amp;#160; entities?” 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What happens if I delete the parent entity without deleting the links ?&lt;/strong&gt;&lt;/p&gt;
It depends on your store . If your database is configured to do a cascade delete on deletion of the parent entity ,you might get away with deleting the entity without removing the links 

&lt;p&gt;The right way to delete the entity is to remove all the links it has with the child entities and then delete the entity itself. 
  &lt;br /&gt;The code would look like this.. 

  &lt;br /&gt;&lt;/p&gt;

&lt;pre class="darkcsharpcode"&gt;Individual existingIndividual = TestContext.Individual.Expand(&lt;span class="str"&gt;&amp;quot;Customer,Contact&amp;quot;&lt;/span&gt;).Take&amp;lt;Individual&amp;gt;(1).First&amp;lt;Individual&amp;gt;();

TestContext.DetachLink(existingIndividual, &lt;span class="str"&gt;&amp;quot;Contact&amp;quot;&lt;/span&gt;, existingIndividual.Contact);
TestContext.DetachLink(existingIndividual, &lt;span class="str"&gt;&amp;quot;Customer&amp;quot;&lt;/span&gt;, existingIndividual.Customer);
TestContext.DeleteObject(existingIndividual);
TestContext.SaveChanges();&lt;/pre&gt;
&lt;style type="text/css"&gt;







.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&lt;strong&gt;Wait !! what’s with the expand there ? 
    &lt;br /&gt;&lt;/strong&gt;Well, if you need to delete the relation , the way to identify the relation or the link is to have both the right and the left end of the relations to be materialized. without the expand , the Contact and the Customer property are null , and we don’t know which relation to delete.In case of 1..1 relations it might be easy to predict based on the relation name , 

  &lt;br /&gt;but wouldn’t be easy in case of 1..n relations. 

  &lt;br /&gt;

  &lt;br /&gt;Well, that’s it from me , In the next part , we shall discuss entities with 1..N relations and how to work with them using the astoria context. 

  &lt;br /&gt;If you have any questions&amp;#160; , leave a comment . If you have any issues with code and need help , please post your query on the astoria forums as I can’t promise that I will be able to reply to emails sent to me directly .The whole team is very active on the forums and the more eyes on a problem the better. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;I will update the code used in&amp;#160; this sample and upload it later. 
  &lt;br /&gt;&lt;/p&gt;
&lt;style type="text/css"&gt;

.darkcsharpcode, .darkcsharpcode pre
{
	padding-top :10px;
	font-size: small;
	color: #d2d200;
	font-family: consolas, "Courier New" , courier, monospace;
	background-color: #2e2e2e; /*white-space: pre;*/
	padding-bottom :10px;
	padding-left :15px;
}
.darkcsharpcode pre
{
	margin: 0em;
}
.darkcsharpcode .rem
{
	color: #00ff00;
}
.darkcsharpcode .kwrd
{
	color: #eaeaac;
	font-size: 11;
	font-weight: bold;
}
.darkcsharpcode .str
{
	color: #cc9393;
}
.darkcsharpcode .op
{
	color: #0000c0;
}
.darkcsharpcode .preproc
{
	color: #cc6633;
}
.darkcsharpcode .asp
{
	background-color: #ffff00;
}
.darkcsharpcode .html
{
	color: #efefef;
}
.darkcsharpcode .attr
{
	color: #dfdfbf;
}
.darkcsharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.darkcsharpcode .lnum
{
	color: #606060;
}&lt;/style&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8680242" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Astoria/default.aspx">Astoria</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Demo/default.aspx">Demo</category><category domain="http://blogs.msdn.com/phaniraj/archive/tags/Documentation/default.aspx">Documentation</category></item></channel></rss>