<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Identity Interface &#187; ria</title>
	<atom:link href="http://jonshern.com/tag/ria/feed/" rel="self" type="application/rss+xml" />
	<link>http://jonshern.com</link>
	<description>I should know better</description>
	<lastBuildDate>Sun, 21 Feb 2010 04:25:31 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Finding a place for WCF RIA in existing applications</title>
		<link>http://jonshern.com/2009/12/17/finding-a-place-for-wcf-ria-in-existing-applications/</link>
		<comments>http://jonshern.com/2009/12/17/finding-a-place-for-wcf-ria-in-existing-applications/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 23:43:56 +0000</pubDate>
		<dc:creator>Jon Shern</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ria]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[entity framework]]></category>
		<category><![CDATA[poco]]></category>
		<category><![CDATA[silvlerlight]]></category>

		<guid isPermaLink="false">http://jonshern.com/2009/12/17/finding-a-place-for-wcf-ria-in-existing-applications/</guid>
		<description><![CDATA[Works with Entity Framework 4.0 CTP 2
My application so far ...
The premise of this application is to create a way for one or more people to create a common practice routine, set goals, and compare their progress.
I started this application with the intention of using Entity Framework 4 and RIA. 
I started having problem with [...]]]></description>
			<content:encoded><![CDATA[<p>Works with Entity Framework 4.0 CTP 2</p>
<p>My application so far ...</p>
<p>The premise of this application is to create a way for one or more people to create a common practice routine, set goals, and compare their progress.</p>
<p>I started this application with the intention of using Entity Framework 4 and RIA. </p>
<p>I started having problem with inserting from the server side, so I decided to start with a more basic model, and work my way into RIA and EF.</p>
<p>My data model looks like this</p>
<p><a href="http://jonshern.com/wp-content/uploads/2009/12/clip_image002.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image002" border="0" alt="clip_image002" src="http://jonshern.com/wp-content/uploads/2009/12/clip_image002_thumb.jpg" width="244" height="239" /></a></p>
<p>I started with the problem of how do I save disconnected entities across a service boundary.</p>
<p>I found that converting to Self Tracking Entities solved this problem very elegantly.</p>
<h5></h5>
<h6>Problem Number 2</h6>
<h6>Option 1(The hard way)</h6>
<p>I want the entire object graph on the client side, and I would like to be able dynamically generate a graph using a collection of Task Items.</p>
<p>I could do this by creating a silvlerlight class library sharing the objects(once they are converted to POCO’s) and using linking to share the objects between layers.</p>
<p>I would then have to build up the structure on the client side, using a series of async loads.</p>
<p>This is a lot of work. I have done it before, and every time I do it, I feel like I just wasted time I will never get back.</p>
<h6>Option 2 - Use RIA and POCO.</h6>
<p>I know that RIA sits in between the Server and the Client </p>
<p><a href="http://jonshern.com/wp-content/uploads/2009/12/clip_image004.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="clip_image004" border="0" alt="clip_image004" src="http://jonshern.com/wp-content/uploads/2009/12/clip_image004_thumb.jpg" width="244" height="85" /></a></p>
<p>(Shamelessly stolen from Brad Abrahams excellent RIA Services video)</p>
<p><strong>So how do I add RIA to this project?</strong></p>
<p>&#160;</p>
<p><strong>Setting up your POCO entities</strong></p>
<p>I have an entity class for Tasks</p>
<pre class="code"><span style="color: blue">namespace </span>PracticeManager.Common.Entities
{
    <span style="color: blue">public class </span><span style="color: #2b91af">Task
    </span>{
        [<span style="color: #2b91af">Key</span>]
        <span style="color: blue">public virtual int </span>Id { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual string </span>Name { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual </span><span style="color: #2b91af">DateTime </span>CreatedTime { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual </span><span style="color: #2b91af">DateTime </span>ModifiedTime { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual string </span>Status { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual string </span>MeasurementUnit { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual string </span>UserName { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public virtual int</span>? CommentId { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

        <span style="color: blue">public </span><span style="color: #2b91af">ICollection</span>&lt;<span style="color: #2b91af">TaskItem</span>&gt; TaskItems { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public </span><span style="color: #2b91af">ICollection</span>&lt;<span style="color: #2b91af">Goal</span>&gt; Goals { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public </span><span style="color: #2b91af">Comment </span>Comment { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public </span><span style="color: #2b91af">ICollection</span>&lt;<span style="color: #2b91af">Taunt</span>&gt; Taunts { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public </span><span style="color: #2b91af">ICollection</span>&lt;<span style="color: #2b91af">Challenge</span>&gt; Challenges { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public </span><span style="color: #2b91af">ICollection</span>&lt;<span style="color: #2b91af">Challenge</span>&gt; Challenges_1 { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }

    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I have my context class.</p>
<pre class="code"><span style="color: blue">namespace </span>PracticeManager.Server.Business.DataContext
{
    <span style="color: blue">public class </span><span style="color: #2b91af">TaskDataContext </span>: <span style="color: #2b91af">ObjectContext
    </span>{
        <span style="color: blue">private </span><span style="color: #2b91af">ObjectSet</span>&lt;<span style="color: #2b91af">Task</span>&gt; _tasks;

        <span style="color: blue">public </span>TaskDataContext(<span style="color: blue">string </span>connectionString)
            : <span style="color: blue">base</span>(connectionString, <span style="color: #a31515">&quot;PracticeModelContainer&quot;</span>)
        {

        }

        <span style="color: blue">public </span><span style="color: #2b91af">ObjectSet</span>&lt;<span style="color: #2b91af">Task</span>&gt; Tasks
        {
            <span style="color: blue">get
            </span>{
                <span style="color: blue">return </span>_tasks ?? (_tasks = <span style="color: blue">base</span>.CreateObjectSet&lt;<span style="color: #2b91af">Task</span>&gt;());
            }

        }

    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p>This covers the data loading portion.</p>
<p><strong>Hooking up RIA Services</strong></p>
<p>In your Web Project add a Domain Service class.</p>
<p>A wizard will appear, I avoided the wizard. I want to do this programmatically.</p>
<p>&#160;</p>
<p>My domain class is pretty simple, for now I just want a list of tasks.</p>
<pre class="code">[<span style="color: #2b91af">EnableClientAccess</span>()]
<span style="color: blue">public class </span><span style="color: #2b91af">PracticeManagerDomainService </span>: <span style="color: #2b91af">DomainService
</span>{
    <span style="color: blue">private </span><span style="color: #2b91af">TaskDataContext </span>taskContext;

    <span style="color: blue">public </span><span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Task</span>&gt; GetTasks()
    {
        <span style="color: blue">var </span>cnxString = <span style="color: #2b91af">ConfigurationManager</span>.ConnectionStrings[<span style="color: #a31515">&quot;PracticeModelContainer&quot;</span>].ConnectionString;
        taskContext = <span style="color: blue">new </span><span style="color: #2b91af">TaskDataContext</span>(cnxString);
        <span style="color: blue">var </span>tasks = taskContext.Tasks;

        <span style="color: blue">return </span>tasks;
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>&#160;</p>
<p>This is far from pretty, I need to move my connection string out of the method, but this will work.</p>
<p><strong>On the client side</strong></p>
<p>In my code behind I have two methods.</p>
<pre class="code"><span style="color: blue">public void </span>LoadTasks()
{
    <span style="color: #2b91af">EntityQuery</span>&lt;<span style="color: #2b91af">Task</span>&gt; taskQuery = _practiceManagerDomainContext.GetTasksQuery();
    _practiceManagerDomainContext.Load(taskQuery, <span style="color: blue">this</span>.OnTasksLoaded, <span style="color: blue">null</span>);
}

<span style="color: blue">private void </span>OnTasksLoaded(<span style="color: #2b91af">LoadOperation</span>&lt;<span style="color: #2b91af">Task</span>&gt; loadOperation)
{
    nameComboBox.ItemsSource = _practiceManagerDomainContext.Tasks;
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>This takes care of the async load and connecting to the service.</p>
<p>The Task object comes across because of its exposure in the domain service class.</p>
<p>The namespace is even the same as the server side, which indicates it is the same object. Not just a service proxy.</p>
<p>Once I call the LoadTasks method, I will get a dropdown populated with tasks.</p>
<p>That is all I need to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://jonshern.com/2009/12/17/finding-a-place-for-wcf-ria-in-existing-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
