<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>.NET Ramblings - Brian Noyes' Blog</title>
  <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/" />
  <link rel="self" href="http://www.softinsight.com/bnoyes/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2010-08-27T21:58:09.2316962-04:00</updated>
  <author>
    <name>Brian Noyes</name>
  </author>
  <subtitle>Occasional mutterings on .NET architecture and development</subtitle>
  <id>http://www.softinsight.com/bnoyes/</id>
  <generator uri="http://www.dasblog.net" version="2.0.7180.0">DasBlog</generator>
  <entry>
    <title>WCF RIA Services Part 6 &amp;ndash; Validating Data posted</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/08/28/WCFRIAServicesPart6NdashValidatingDataPosted.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,a8fa02a5-e4d9-4182-8bf2-92b0d17caf61.aspx</id>
    <published>2010-08-27T21:58:09.2316962-04:00</published>
    <updated>2010-08-27T21:58:09.2316962-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Part 6 of my series on WCF RIA Services is now live here:
</p>
        <p>
          <a title="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-6-Validating-Data.aspx" href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-6-Validating-Data.aspx">http://www.silverlightshow.net/items/WCF-RIA-Services-Part-6-Validating-Data.aspx</a>
        </p>
        <p>
In this episode, I explore the awesome validation infrastructure of RIA Services,
one of my favorite benefits of RIA Services. I show how to use the built-in validation
attributes of the System.ComponentModel.DataAnnotations namespace on both the client
and server side, how to use custom validation via attributes, how to invoke validation
logic on the server side and return errors that get automatically associated with
the entities client side, and how to use Invoke methods to call async validation logic
from the client.
</p>
        <p>
Check it out!
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=a8fa02a5-e4d9-4182-8bf2-92b0d17caf61" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Hidden Toolbox Search feature in VS 2010</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/08/21/HiddenToolboxSearchFeatureInVS2010.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,1a5cfc3c-4c68-489b-922f-d6776e22a5d5.aspx</id>
    <published>2010-08-21T10:51:17.4637907-04:00</published>
    <updated>2010-08-21T10:51:17.4637907-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday I was getting frustrated wading through the dozens of Silverlight controls
in my toolbox trying to spot one I needed, and it occurred to me that there “ought
to be an add-in to search the toolbox”. Just to make sure I wasn’t missing something,
I contacted <a href="http://karlshifflett.wordpress.com/" target="_blank">Karl Shifflett</a> from
the Cider team, who has written some awesome extensions to Cider and the XAML editor
himself. He reached out to the right people on the VS team, and lo and behold, there
is already a hidden search feature there.
</p>
        <p>
You can <a href="http://blogs.msdn.com/b/visualstudio/archive/2009/10/26/toolbox-search.aspx" target="_blank">read
about it here</a>. Thanks Karl and Josh!!
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=1a5cfc3c-4c68-489b-922f-d6776e22a5d5" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Upcoming WCF Master Class in Minnesota</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/08/17/UpcomingWCFMasterClassInMinnesota.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,b4ca0fb2-a8fa-4f3e-b04a-f9be3ac5cf26.aspx</id>
    <published>2010-08-17T14:51:39.7504994-04:00</published>
    <updated>2010-08-17T14:51:39.7504994-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
From October 11-15 I’ll be conducting a WCF Master Class in Minneapolis. This class
covers the breadth and depth of WCF all in one week. You can find the <a href="http://www.benchmarklearning.com/Courses/CrsDetail.aspx?C=IDEWCFMaster" target="_blank">course
information here</a>.
</p>
        <p>
If you want to get to the expert level with WCF in a week’s span, this is the class
for you. We have been teaching an evolving version of this class since before WCF
was released in 2006. It gets rave reviews every time, as long as you are not opposed
to some hard core, in depth, fill your brain until it is ready to burst kind of learning.
</p>
        <p>
If you have any questions about the content, you can contact me on twitter @briannoyes.
</p>
        <p>
Hope to see you there.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=b4ca0fb2-a8fa-4f3e-b04a-f9be3ac5cf26" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WCF RIA Services Part 5 is out</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/08/17/WCFRIAServicesPart5IsOut.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,4e5540d0-e520-4618-993f-ad7459e89f12.aspx</id>
    <published>2010-08-17T13:38:47.497232-04:00</published>
    <updated>2010-08-17T13:38:47.497232-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p align="left">
Part 5 of my 10 part series on WCF RIA Services is now up on The Silverlight Show
at <a title="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-5-Metadata-and-Shared-Classes.aspx" href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-5-Metadata-and-Shared-Classes.aspx">http://www.silverlightshow.net/items/WCF-RIA-Services-Part-5-Metadata-and-Shared-Classes.aspx</a>.
</p>
        <p align="left">
In this article, I explain the role and use of metadata classes to add attributes
and functionality to existing entity classes that you cannot easily modify directly,
such as the properties on an Entity Framework entity. Additionally, I show how you
can define chunks of shared code on the server side and how they become available
client side through the RIA Services code generation.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=4e5540d0-e520-4618-993f-ad7459e89f12" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WCF RIA Services Part 4 &amp;ndash; MVVM articles is live</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/08/04/WCFRIAServicesPart4NdashMVVMArticlesIsLive.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,3d4820e3-ba06-4413-8498-865d53d38881.aspx</id>
    <published>2010-08-04T12:11:27.1328786-04:00</published>
    <updated>2010-08-04T12:11:27.1328786-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Part 4 of my series of WCF RIA Services is now live on <a href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-4-Integrating-with-the-Model-View-ViewModel-Pattern.aspx" target="_blank">The
Silverlight Show here</a>.
</p>
        <p>
In this episode, I focus on using RIA Services in an MVVM world. That includes not
using the DomainDataSource anymore and encapsulating the domain context in your view
model and making the calls through it from there. You can expose the entity collections
from the domain context directly as properties on the view model because they are
a collection that raises CollectionChanged events when the underlying data changes,
and the entities implement INotifyPropertyChanged so they participate nicely with
data binding. They also implement INotifyDataErrorInfo and integrate nicely with the
Silverlight data binding mechanisms.
</p>
        <p>
The only downside to that approach is that you cannot easily mock out the domain context
dependency, so it makes it hard to unit test your view model, which is one of the
motivations for using the view model pattern in the first place. At the end of the
article I point to a recommended solution from the RIA Services team – specifically
to mock out the DomainClient that sits on the other side of the domain context and
makes the actual service calls. That is not super easy, but it is at least a solution.
I’m going to expand my sample to include that approach in Part 8 of the series.
</p>
        <p>
Check it out and let me know what you think.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=3d4820e3-ba06-4413-8498-865d53d38881" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Silverlight TV: Understanding the Value of Prism</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/23/SilverlightTVUnderstandingTheValueOfPrism.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,44767d05-4984-4c81-a54c-0718d1ed0001.aspx</id>
    <published>2010-07-22T20:59:18.428077-04:00</published>
    <updated>2010-07-22T20:59:18.428077-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was recently interviewed on the Silverlight TV show hosted by John Papa and the
episode went live today.
</p>
        <p>
          <a title="http://channel9.msdn.com/shows/SilverlightTV/Understanding-the-Value-of-Prism-Silverlight-TV-37/" href="http://channel9.msdn.com/shows/SilverlightTV/Understanding-the-Value-of-Prism-Silverlight-TV-37/">http://channel9.msdn.com/shows/SilverlightTV/Understanding-the-Value-of-Prism-Silverlight-TV-37/</a>
        </p>
        <p>
In the interview, we discuss some of the motivations for adopting Prism:
</p>
        <ul>
          <li>
Managing large projects</li>
          <li>
Distributed teams</li>
          <li>
Packaging functionality for different deployments per customer</li>
          <li>
Separation of concerns for maintainability</li>
          <li>
Testability</li>
          <li>
Extensibility</li>
        </ul>
        <p>
I quickly walk through the features and how they manifest themselves in your solutions.
I also discuss a little of what the team is working on in Prism 4 – specifically the
MVVM pattern and using MEF for modularity.
</p>
        <p>
Check it out and let me know what you think!
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=44767d05-4984-4c81-a54c-0718d1ed0001" />
      </div>
    </content>
  </entry>
  <entry>
    <title>San Diego Connected Systems/Architect SIG &amp;ndash; Slides and Demos</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/15/SanDiegoConnectedSystemsArchitectSIGNdashSlidesAndDemos.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,550da06c-4c9c-45e0-8dc1-63e4c9b20f33.aspx</id>
    <published>2010-07-14T22:18:29.6616381-04:00</published>
    <updated>2010-07-14T22:18:29.6616381-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last night I spoke to a great crowd at a joint meeting of the San Diego Connected
Systems and Architecture SIGs. I talked about WCF RIA Services and focused on the
internals of what is going on with deferred execution queries, metadata for entities,
and the services under the covers, as well as exposing OData, SOAP, and JSON endpoints
and consuming them.
</p>
        <p>
Here are the <a href="http://www.softinsight.com/downloads/INETA/WCFRIAServicesInsideOut.pdf" target="_blank">slides</a> and <a href="http://www.softinsight.com/downloads/INETA/WCFRIAServicesInsideOut.zip" target="_blank">demos</a>.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=550da06c-4c9c-45e0-8dc1-63e4c9b20f33" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Los Angeles .NET Users Group Slides and Demos</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/15/LosAngelesNETUsersGroupSlidesAndDemos.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,f942ed82-4a9a-4ca9-80d3-e79f63837822.aspx</id>
    <published>2010-07-14T22:10:03.1374564-04:00</published>
    <updated>2010-07-14T22:10:03.1374564-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I gave a talk on Monday evening at the Los Angeles .NET Users Group on WCF RIA Services,
MVVM, and MEF. I was insanely ambitious thinking I could cover all those in one talk,
but it was a fun talk nonetheless. It was a very interactive crowd with a lot of great
questions about Silverlight in general, RIA Services, Entity Framework and other broader
technology topics.
</p>
        <p>
Here are the <a href="http://www.softinsight.com/downloads/INETA/BuildLooselyCoupledSilverlightBusinessApplications.pdf">slides</a> and <a href="http://www.softinsight.com/downloads/INETA/RIAServicesMVVMMEFDEmos.zip" target="_blank">demos</a>.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=f942ed82-4a9a-4ca9-80d3-e79f63837822" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Interview on the Silverlight Show</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/11/InterviewOnTheSilverlightShow.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,c3fd37cd-e96a-42a2-aac2-fea9939f994f.aspx</id>
    <published>2010-07-11T10:32:28.7941638-04:00</published>
    <updated>2010-07-11T10:32:28.7941638-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In conjunction with the <a href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-1-Getting-Started.aspx" target="_blank">10
part series on WCF RIA Services</a> in am part way through writing for the Silverlight
Show, I also did a short interview with them about RIA Services, Silverlight in general,
and my background. You can find that interview here: <a title="http://www.silverlightshow.net/items/SilverlightShow-Interview-Featured-Article-Author-Brian-Noyes.aspx" href="http://www.silverlightshow.net/items/SilverlightShow-Interview-Featured-Article-Author-Brian-Noyes.aspx">http://www.silverlightshow.net/items/SilverlightShow-Interview-Featured-Article-Author-Brian-Noyes.aspx</a></p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=c3fd37cd-e96a-42a2-aac2-fea9939f994f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Windows to Mac transition &amp;ndash; Not for me</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/08/WindowsToMacTransitionNdashNotForMe.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,ae98eb98-7def-43af-bc53-8f41a0d28a30.aspx</id>
    <published>2010-07-08T12:55:03.1176269-04:00</published>
    <updated>2010-07-08T12:55:03.1176269-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not too long ago I made the plunge and bought a MacBook Pro, the first Mac I have
ever owned. I did so for two reasons. First and foremost, I am starting to develop
applications for the iPhone and iPad (two devices I can’t live without), and developing
on a Mac is the only choice thanks to the closed platform and development tools approach
of Apple. Secondly, I thought it would be interesting to see what computer life is
like on the other side of the fence. I’ve heard so many stories of how great the Mac
is, I thought I would try to experience it first hand.
</p>
        <p>
So for the last month I have tried using my MacBook Pro as my primary machine – not
booting to Windows, but running Mac OS X and using Parallels to get to the Windows
apps I can’t live without. 
</p>
        <p>
After a month, I’m switching back to my Dell Latitude E6500 as my primary machine
and my MacBook Pro will just be used for reason #1 – developing for iPhone/iPad.
</p>
        <p>
When I tweeted (@briannoyes) that I was switching back, I got a lot of “why??” questions,
so I thought I would share my experience for others who are pondering a similar change.
</p>
        <p>
Some important caveats up front:
</p>
        <ul>
          <li>
I am first and foremost a Windows developer and software architect. That is my profession
and my passion and what I have been focusing on for almost two decades.</li>
          <li>
I have dozens of Windows applications that I used at least once a month and at least
20 or so that I use every week. While I realize there are many equivalent Mac programs
for many of those, I don’t want to have to buy all of those, and for many there is
not (i.e. Windows development tools).</li>
          <li>
I don’t just work on one machine and have no intention of switching all of my computing
to Apple. While I love my iPad and iPhone, I have a Windows 7 desktop machine in my
home office that I use when not traveling, and when traveling (75%+ of my time) I
often carry a second laptop for various reasons and that one would certainly be a
Windows machine.</li>
          <li>
From a performance perspective, my point of comparison and what I have switched back
to is a 6 month old Dell Latitude E6500 that is maxed out. My MacBook Pro has slightly
better hardware specs (i7 processor), but same 256 GB SSD drive and 8 GB memory.</li>
          <li>
I was afraid of using Boot Camp to boot to Windows directly because of witnessing
and hearing about numerous projection issues when running Windows through Boot Camp
on Mac Books. A significant majority of my professional work involves projecting (teaching,
consulting, presenting at conferences and user groups). I can’t travel with a machine
I can’t trust will project anywhere through any projector with no issues.</li>
          <li>
I’ve been using Office 2010 for a while, so that is my standard of comparison for
routine business tasks (email, writing, presentations, spreadsheets).</li>
        </ul>
        <p>
So what did I like:
</p>
        <ul>
          <li>
General user experience is very nice at the OS level. 
</li>
          <li>
iTunes runs much smoother on the Mac than on Windows</li>
          <li>
Parallels integration with the Mac OS is very smooth and seamless</li>
          <li>
Er… ummm… OK, nothing else jumping out that I found superior to anything I do on Windows
7.</li>
        </ul>
        <p>
What I did not like:
</p>
        <ul>
          <li>
Built in apps (email, calendar, etc.) had no where near the functionality or user
experience of Office 2010. Office 2008 for Mac is not as good either, and I still
have to co-exist with several Windows PCs. Worrying about file conversions and potential
data loss is just not worth it.</li>
          <li>
A lot of my Windows apps could not run from the shared Mac OS folders, so had to move
things onto the virtual C: drive a lot to get things to run, aggrevating file synchronization
issues and leading to duplicate files and drive usage.</li>
          <li>
Keyboard lacks many common keys that PC keyboards have (Del, Home, End, PgUp, PgDn,
etc). You have to use the Fn key to get other keys to do those things, and you have
to use the Fn key to get the function keys to act as function keys instead of volume,
etc shortcut keys. These keys are all way too important to me as a coder to have to
use the extra key to get to them, especially since I also work a lot on PCs and have
to switch my brain back and forth. Likewise the differences of what the Control, Alt/option,
and Command keys do in Mac vs Windows (in parallels) drive me bonkers trying to keep
straight. Many a wasted minute thinking I copied things to the clipboard and I didn’t
or getting things to select correctly.</li>
          <li>
Perf: even though the Mac had a better processor and equal memory / disk, everything
felt a lot more sluggish on it, and I’m not just talking about the Windows apps running
in Parallels. Copying files to external USB drives (which I had to do a lot for syncing
files between machines) was significantly slower than on PC.</li>
          <li>
File synchronization: I use Dropbox to sync files between my machines, but the difference
in file systems led to some oddities that that were annoying at best and could lead
to data loss if not closely managed. Syncing with external drives also took closer
attention than I wanted to give it. I don’t want to have to think at all about moving
files around, and from PC to PC I don’t.</li>
        </ul>
        <p>
So bottom line, I decided I can’t live on a Mac as my primary machine for the reasons
outlined above. I am convinced that if you only have to use one machine and are willing
to invest in getting all the apps you need as Mac apps, and can live 80% or more of
your computer life using Mac apps, then it is a nice platform. That is just not me,
so I am happily back in my comfort zone on all Windows 7 machines + a MacBook Pro
as an iPad/iPhone development box.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=ae98eb98-7def-43af-bc53-8f41a0d28a30" />
      </div>
    </content>
  </entry>
  <entry>
    <title>WCF RIA Services Part 3 &amp;ndash; Updating Data</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/07/05/WCFRIAServicesPart3NdashUpdatingData.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,dddf4af6-7dbe-4c14-9ae4-c0f14520bc6f.aspx</id>
    <published>2010-07-05T15:23:02.3824399-04:00</published>
    <updated>2010-07-05T15:23:02.3824399-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The third part of my series on WCF RIA Services went up a few days ago, you can check
it out here:
</p>
        <p>
          <a title="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-3-Updating-Data.aspx" href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-3-Updating-Data.aspx">http://www.silverlightshow.net/items/WCF-RIA-Services-Part-3-Updating-Data.aspx</a>
        </p>
        <p>
This one starts off with a quick coverage of one important aspect of querying that
I did not have room for in Part 2 – expression trees and deferred execution, and what
they can do for you with RIA Services. I show how you can formulate a query on the
client side based on the expression tree returned by a query method and that is what
executes on the server side.
</p>
        <p>
Then I get into the way updating (insert, update, and delete really) works in RIA
Services. I discuss the way the domain context caches data and tracks its changes,
and then only sends the modified entities back in a batch when you call SubmitChanges
on the domain context. I also talk a little about the async API of the domain context,
which I then followed up on with this post:
</p>
        <p>
          <a title="http://www.softinsight.com/bnoyes/2010/06/29/QueryingWCFRIAServicesAndHandlingAsyncResults.aspx" href="http://www.softinsight.com/bnoyes/2010/06/29/QueryingWCFRIAServicesAndHandlingAsyncResults.aspx">http://www.softinsight.com/bnoyes/2010/06/29/QueryingWCFRIAServicesAndHandlingAsyncResults.aspx</a>
        </p>
        <p>
Enjoy!
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=dddf4af6-7dbe-4c14-9ae4-c0f14520bc6f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Querying WCF RIA Services and handling async results</title>
    <link rel="alternate" type="text/html" href="http://www.softinsight.com/bnoyes/2010/06/29/QueryingWCFRIAServicesAndHandlingAsyncResults.aspx" />
    <id>http://www.softinsight.com/bnoyes/PermaLink,guid,182d02e2-4e6f-408d-964a-e2a508803f03.aspx</id>
    <published>2010-06-29T16:10:25.5021994-04:00</published>
    <updated>2010-06-29T16:11:10.0945224-04:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I had a good question in the comments of <a href="http://www.silverlightshow.net/items/WCF-RIA-Services-Part-2-Querying-Data.aspx" target="_blank">Part
2</a> of my series on WCF RIA Services that I thought I would answer here so more
could find the information.
</p>
        <p>
To paraphrase the question: “How can I retrieve a set of entities into my client and
process them when the retrieval is complete?
</p>
        <p>
I didn’t go into detail on the latter part of this in the article because of space
limitations. But basically the answer is that you can be notified of the completion
of any async operation (Load and SubmitChanges primarily) that you call on a RIA Services
domain context. There are really two programming models, but I’ll just show one for
now as the other is very similar.
</p>
        <p>
When you call DomainContext.Load, RIA services executes the retrieval in the background
and the call is non-blocking to the calling thread. But often you need to get those
results, do some processing on them, and then move on to make another query or do
something else.
</p>
        <p>
An easy way to handle things is to use an overload of Load (and SubmitChanges) that
takes a callback delegate that will be called when the async work is complete. This
model is slightly different than the two other familiar async patterns in .NET: BeginXXX/EndXXX
method pairs and XXXAsync/XXXCompleted method/event.
</p>
        <p>
In the RIA Services async pattern, you can pass an Action&lt;XXX&gt; delegate to the
async method you are calling, and that target method will be executed when the async
operation is complete. It will pass you results and any error information if applicable.
</p>
        <p>
In the case of a Load call, the code would look something like this:
</p>
        <pre class="csharpcode">
          <span class="kwrd">private</span>
          <span class="kwrd">void</span> RetrieveAndProcessTasks()
{ TasksDomainContext context = <span class="kwrd">new</span> TasksDomainContext();
EntityQuery&lt;Task&gt; query = context.GetTasksQuery(); Action&lt;LoadOperation&lt;Task&gt;&gt;
completeProcessing = <span class="kwrd">delegate</span>(LoadOperation&lt;Task&gt;
loadOp) { <span class="kwrd">if</span> (!loadOp.HasError) { ProcessTasks(loadOp.Entities);
} <span class="kwrd">else</span> { LogAndNotify(loadOp.Error); } }; LoadOperation&lt;Task&gt;
loadOperation = context.Load(query.Where(t=&gt;t.EndDate &gt; DateTime.Now),completeProcessing,<span class="kwrd">null</span>);
} <span class="kwrd">private</span><span class="kwrd">void</span> ProcessTasks(IEnumerable&lt;Task&gt;
entities) { <span class="rem">// Do what you need to do</span> } <span class="kwrd">private</span><span class="kwrd">void</span> LogAndNotify(Exception
error) { <span class="rem">// Log the error and notify user if appropriate</span> }</pre>
        <style type="text/css">

.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; }</style>
        <p>
Before calling Load on the domain context, you set up an Action&lt;LoadOperation&lt;T&gt;&gt;
delegate to point to a handling method with the signature void TargetMethod(LoadOperation&lt;T&gt;
op). In this example I do that with an anonymous method that checks whether there
are any errors, and if not hands off to a processing method the entities that were
returned. If there is an error, it hands off the Exception to a handling method as
well. 
</p>
        <p>
Then it is just a matter of calling Load and passing that delegate as a second argument
(the first is always the EntityQuery you want to execute), and a final argument that
is an arbitrary state object, similar to the Begin/End signatures of the original
.NET async pattern.
</p>
        <p>
Unfortunately there is no easy way to shield you entirely from the async nature of
service calls in Silverlight if you want to do something other than data bind to the
results immediately after the load occurs.
</p>
        <img width="0" height="0" src="http://www.softinsight.com/bnoyes/aggbug.ashx?id=182d02e2-4e6f-408d-964a-e2a508803f03" />
      </div>
    </content>
  </entry>
</feed>