<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Randolph Cabral's Weblog</title>
	<atom:link href="http://randolphcabral.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://randolphcabral.wordpress.com</link>
	<description>...beauty is just a dimmer switch away...</description>
	<lastBuildDate>Thu, 28 Apr 2011 22:22:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='randolphcabral.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Randolph Cabral's Weblog</title>
		<link>http://randolphcabral.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://randolphcabral.wordpress.com/osd.xml" title="Randolph Cabral&#039;s Weblog" />
	<atom:link rel='hub' href='http://randolphcabral.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Back to Blogging!</title>
		<link>http://randolphcabral.wordpress.com/2011/04/28/back-toblogging/</link>
		<comments>http://randolphcabral.wordpress.com/2011/04/28/back-toblogging/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 22:22:45 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
		
		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=50</guid>
		<description><![CDATA[After a few years hiatus, I&#8217;ve decided to start blogging again.  Please visit my new blog at http://randolphcabral.tumblr.com. This time, I plan to blog more regularly and include other topics beyond programming but still relating to technology. Make no mistake. I will most certainly continue to blog about programming, but I want to expand the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=50&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a few years hiatus, I&#8217;ve decided to start blogging again.  Please visit my new blog at <a title="@randolphcabral" href="http://randolphcabral.tumblr.com">http://randolphcabral.tumblr.com</a>. This time, I plan to blog more regularly and include other topics beyond programming but still relating to technology. Make no mistake. I will most certainly continue to blog about programming, but I want to expand the conversation to include other technology interests as well. So, if you&#8217;re up for some technical discourse I hope you&#8217;ll drop by the new blog and sling your thoughts my way.</p>
<p>One last thing, I will leave this blog up as an archive of my early technical musings.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=50&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2011/04/28/back-toblogging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Raising INotifyPropertyChanged Events with an Extension Method</title>
		<link>http://randolphcabral.wordpress.com/2009/10/02/raising-inotifypropertychanged-events-with-an-extension-method/</link>
		<comments>http://randolphcabral.wordpress.com/2009/10/02/raising-inotifypropertychanged-events-with-an-extension-method/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 18:57:49 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[ComponentModel]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=40</guid>
		<description><![CDATA[Okay, I'm probably not the only one out there that is tired of writing the NotifyPropertyChanged() method in all my ViewModel classes.  And I'm probably not the only one who is afraid of magical strings. So today, I'm posting a simple re-usable extension method that targets all classes that implement the INotifyPropertyChanged interface.  And while were at it, why not take advantage of lambda expressions to give us the benefit of  Visual Studio's intellisense/automatic code completion features as well.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=40&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Okay, I&#8217;m probably not the only one out there that is tired of writing the NotifyPropertyChanged() method in all my entity and ViewModel classes.  And I&#8217;m probably not the only one who is afraid of magical strings. So today, I&#8217;m posting a simple reusable extension method that targets all classes that implement the INotifyPropertyChanged interface.  And while we&#8217;re at it, why not take advantage of lambda expressions to give us the benefit of Visual Studio&#8217;s intellisense/automatic code completion features as well.</p>
<p><strong>Take 1 : The Way It Is</strong></p>
<p>Let&#8217;s start with the standard implementation of the INotifyPropertyChanged interface. The following should look familiar. Notice that each setter has a call to the NotifyPropertyChanged() method which needs a magic string to pass to the event args.  Careful! If you misspell or mis-case the magic string, you&#8217;re gonna get smacked with a runtime exception if you aren&#8217;t paying attention. If you&#8217;re into that sort of thing, you should probably find professional help.</p>
<div style="font-family:Courier New;font-size:9pt;color:black;background:white;">
<pre style="margin:0;"><span style="color:#2b91af;">    1</span>   <span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Camel</span> : <span style="color:#2b91af;">INotifyPropertyChanged</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    2</span>   {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    3</span>     <span style="color:blue;">private</span> <span style="color:blue;">int</span> _Age;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    4</span>     <span style="color:blue;">public</span> <span style="color:blue;">int</span> Age</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    5</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    6</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    7</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    8</span>         <span style="color:blue;">return</span> _Age;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    9</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   10</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   11</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   12</span>         _Age = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   13</span>         NotifyPropertyChanged(<span style="color:#a31515;">"Age"</span>); <span style="color:green;">//What's with the magic strings?</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   14</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   15</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   16</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   17</span>     <span style="color:blue;">private</span> <span style="color:blue;">string</span> _Name;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   18</span>     <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   19</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   20</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   21</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   22</span>         <span style="color:blue;">return</span> _Name;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   23</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   24</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   25</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   26</span>         _Name = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   27</span>         NotifyPropertyChanged(<span style="color:#a31515;">"Mane"</span>); <span style="color:green;">//This may result in a runtime exception.</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   28</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   29</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   30</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   31</span>     <span style="color:blue;">private</span> <span style="color:blue;">bool</span> _HasGingivitis;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   32</span>     <span style="color:blue;">public</span> <span style="color:blue;">bool</span> HasGingivitis</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   33</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   34</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   35</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   36</span>         <span style="color:blue;">return</span> _HasGingivitis;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   37</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   38</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   39</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   40</span>         _HasGingivitis = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   41</span>         NotifyPropertyChanged(<span style="color:#a31515;">"HasGingivitis"</span>);</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   42</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   43</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   44</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   45</span>     <span style="color:green;">//Do I really need to write this method for all of my classes?? I'm too lazy.</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   46</span>     <span style="color:blue;">private</span> <span style="color:blue;">void</span> NotifyPropertyChanged(<span style="color:blue;">string</span> propertyName)</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   47</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   48</span>       <span style="color:blue;">if</span> (<span style="color:blue;">null</span> != PropertyChanged)</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   49</span>         PropertyChanged(<span style="color:blue;">this</span>, <span style="color:blue;">new</span> <span style="color:#2b91af;">PropertyChangedEventArgs</span>(propertyName));</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   50</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   51</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   52</span> <span style="color:blue;">    #region</span> INotifyPropertyChanged Members</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   53</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   54</span>     <span style="color:blue;">public</span> <span style="color:blue;">event</span> <span style="color:#2b91af;">PropertyChangedEventHandler</span> PropertyChanged;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   55</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   56</span> <span style="color:blue;">    #endregion</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   57</span>   }</pre>
</div>
<p><strong>Take 2 : The Way I Want It To Be</strong></p>
<p>Now let’s look at  a sample using the extension method implementation. With this implementation our beloved magic strings are replaced with intellisense-friendly lambda expressions. Notice that the calls to the extension method requires the use of &#8216;this.&#8217; syntax. Additionally, the extension method needs a reference to the delegate in order to fire the event.</p>
<div style="font-family:Courier New;font-size:9pt;color:black;background:white;">
<pre style="margin:0;"><span style="color:#2b91af;">    1</span>   <span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Camel</span> : <span style="color:#2b91af;">INotifyPropertyChanged</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    2</span>   {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    3</span>     <span style="color:blue;">private</span> <span style="color:blue;">int</span> _Age;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    4</span>     <span style="color:blue;">public</span> <span style="color:blue;">int</span> Age</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    5</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    6</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    7</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    8</span>         <span style="color:blue;">return</span> _Age;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    9</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   10</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   11</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   12</span>         _Age = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   13</span>         <span style="color:blue;">this</span>.NotifyPropertyChanged(e =&gt; e.Age, PropertyChanged);</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   14</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   15</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   16</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   17</span>     <span style="color:blue;">private</span> <span style="color:blue;">string</span> _Name;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   18</span>     <span style="color:blue;">public</span> <span style="color:blue;">string</span> Name</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   19</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   20</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   21</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   22</span>         <span style="color:blue;">return</span> _Name;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   23</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   24</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   25</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   26</span>         _Name = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   27</span>         <span style="color:blue;">this</span>.NotifyPropertyChanged(e =&gt; e.Name, PropertyChanged);</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   28</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   29</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   30</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   31</span>     <span style="color:blue;">private</span> <span style="color:blue;">bool</span> _HasGingivitis;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   32</span>     <span style="color:blue;">public</span> <span style="color:blue;">bool</span> HasGingivitis</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   33</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   34</span>       <span style="color:blue;">get</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   35</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   36</span>         <span style="color:blue;">return</span> _HasGingivitis;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   37</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   38</span>       <span style="color:blue;">set</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   39</span>       {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   40</span>         _HasGingivitis = <span style="color:blue;">value</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   41</span>         <span style="color:blue;">this</span>.NotifyPropertyChanged(e =&gt; e.HasGingivitis, PropertyChanged);</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   42</span>       }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   43</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   44</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   45</span> <span style="color:blue;">    #region</span> INotifyPropertyChanged Members</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   46</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   47</span>     <span style="color:blue;">public</span> <span style="color:blue;">event</span> <span style="color:#2b91af;">PropertyChangedEventHandler</span> PropertyChanged;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   48</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   49</span> <span style="color:blue;">    #endregion</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   50</span>   }</pre>
</div>
<p><strong>Where the Magic Happens</strong></p>
<p><strong></strong>Here&#8217;s the implementation for the extension method.  It&#8217;s pretty straightforward and self-explanatory so I&#8217;ll save you the time and just leave it at that. Have fun with it!</p>
<div style="font-family:Courier New;font-size:9pt;color:black;background:white;">
<pre style="margin:0;"><span style="color:#2b91af;">    1</span> <span style="color:blue;">namespace</span> Extensions</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    2</span> {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    3</span>   <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">ExtensionMethods</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    4</span>   {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    5</span>     <span style="color:blue;">public</span> <span style="color:blue;">static</span> <span style="color:blue;">void</span> NotifyPropertyChanged&lt;TEntity&gt;(<span style="color:blue;">this</span> TEntity entity,</pre>
<pre style="margin:0;"><span style="color:#2b91af;">            Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;TEntity, <span style="color:blue;">object</span>&gt;&gt; propertySelector,</pre>
<pre style="margin:0;"><span style="color:#2b91af;">            PropertyChangedEventHandler</span> propertyChanged)</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    6</span>       <span style="color:blue;">where</span> TEntity : <span style="color:#2b91af;">INotifyPropertyChanged</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">    7</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    8</span>       <span style="color:blue;">if</span> (propertyChanged != <span style="color:blue;">null</span>)</pre>
<pre style="margin:0;"><span style="color:#2b91af;">    9</span>         propertyChanged(entity,</pre>
<pre style="margin:0;"><span style="color:blue;">                new</span> <span style="color:#2b91af;">PropertyChangedEventArgs</span>(FormatPropertyName(propertySelector)));</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   10</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   11</span></pre>
<pre style="margin:0;"><span style="color:#2b91af;">   12</span>     <span style="color:blue;">static</span> <span style="color:blue;">string</span> FormatPropertyName&lt;TEntity&gt;</pre>
<pre style="margin:0;">            (<span style="color:#2b91af;">Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;TEntity, <span style="color:blue;">object</span>&gt;&gt; propertySelector)</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   13</span>     {</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   14</span>       <span style="color:blue;">var</span> memberExpression = propertySelector.Body <span style="color:blue;">as</span> <span style="color:#2b91af;">MemberExpression</span>;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   15</span>       <span style="color:blue;">return</span> memberExpression.Member.Name;</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   16</span>     }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   17</span>   }</pre>
<pre style="margin:0;"><span style="color:#2b91af;">   18</span> }</pre>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=40&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2009/10/02/raising-inotifypropertychanged-events-with-an-extension-method/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Business Objects Enterprise 11.5 Shared Secret&#8230;Shhhh!</title>
		<link>http://randolphcabral.wordpress.com/2008/05/29/business-objects-enterprise-115-shared-secretshhhh/</link>
		<comments>http://randolphcabral.wordpress.com/2008/05/29/business-objects-enterprise-115-shared-secretshhhh/#comments</comments>
		<pubDate>Thu, 29 May 2008 21:52:18 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[BOXI .NET SDK]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[BOE XI]]></category>
		<category><![CDATA[BOXI]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=34</guid>
		<description><![CDATA[I had to blog about this because I&#8217;m sure many of you who need to deal with the BOE XI .NET APIs will find this one useful.  Also because I know I&#8217;m going to need this info again at some point and I figure this is the best place to memorialize this knowledge.  In this [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=34&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had to blog about this because I&#8217;m sure many of you who need to deal with the BOE XI .NET APIs will find this one useful.  Also because I know I&#8217;m going to need this info again at some point and I figure this is the best place to memorialize this knowledge.  In this post, I&#8217;ll specifically talk about my experience in enabling trusted authentication to the BOE server using &#8216;secEnterprise&#8217; security with the BOXI .NET APIs.  A note for Java developers &#8211; I think most of the code samples should work with the exception of the use of concrete types.  Most of the types are replaced with interfaces in Java and the naming convention is such that you should be able to add an &#8216;I&#8217; to the beginning of the type names.  Why they didn&#8217;t do this for .NET is a mystery to me.</p>
<p>The first thing we need to do is open the secEnterprise folder on both the client machine and on the server.  The path is as follows &#8211; [Drive:\Business Objects Installation Folder]\BusinessObjects Enterprise 11.5\win32_x86\plugins\auth\secEnterprise.  Here you should find a single file named secEnterprise.dll.  If you don&#8217;t see this file, or folder, you are going to need to install the BOE XI R2 SP2 client tools.  The one I installed is dated 3/6/2007.  Once installed, the above mentioned files and folders should be present.  Once located, it&#8217;s time to add a new text file and name it &#8220;TrustedPrincipal.conf&#8221;.  Using your favorite plain vanilla text editor (I use notepad) add a line that reads, &#8220;SecretPassword=[word or phrase without spaces using 0-9, A-Z, and a-z characters only]&#8220;.  Obviously, the word/phrase must match on the client and server installations. NOTE:  If the server already has this file and a password/phrase is already present, do not change it!  I recommend copying the server value to your client file.  But, if you&#8217;re feeling macho and absolutely need to change it, a reboot of the server may be required to flush the old value from cache.</p>
<p>Now, the following code sample will allow you to &#8220;impersonate&#8221; any user that has been granted access to the BOE server using the trusted principal method.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">SessionMgr</span> sess = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SessionMgr</span>();</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">TrustedPrincipal</span> tp = sess.CreateTrustedPrincipal(<span style="color:#a31515;">&#8220;John.Doe&#8221;</span>, <span style="color:#a31515;">&#8220;YourBoxiServerName&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">EnterpriseSession</span> esess = sess.LogonTrustedPrincipal(tp);</p>
</div>
<p>With a little bit more code, we can use the current thread to detect the security principal and parse the user name so we can pass it in as a method argument.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">string</span> identName = System.Threading.<span style="color:#2b91af;">Thread</span>.CurrentPrincipal.Identity.Name;</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">if</span> (<span style="color:#0000ff;">string</span>.IsNullOrEmpty(identName))</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> System.Security.<span style="color:#2b91af;">SecurityException</span>(<span style="color:#a31515;">&#8220;Not logged in!&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">int</span> startIdx = identName.IndexOf(<span style="color:#a31515;">&#8216;\\&#8217;</span>) + 1;</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">string</span> username = identName.Substring(startIdx, identName.Length &#8211; startIdx);</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">SessionMgr</span> sess = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SessionMgr</span>();</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">TrustedPrincipal</span> tp = sess.CreateTrustedPrincipal(username, <span style="color:#a31515;">&#8220;YourBoxiServerName&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">EnterpriseSession</span> esess = sess.LogonTrustedPrincipal(tp);</p>
</div>
<p>One last thing to note is that I&#8217;m referencing a combination of version 11.5.3300.0 and 11.5.3700.0 of the CrystalDecisions assemblies.</p>
<p>Well, that&#8217;s it.  I hope someone out there finds this post helpful.  <!--EndFragment--></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/34/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/34/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=34&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/05/29/business-objects-enterprise-115-shared-secretshhhh/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring N-Tier Architecture with LINQ to SQL (Part 4 of n)</title>
		<link>http://randolphcabral.wordpress.com/2008/05/21/exploring-n-tier-architecture-with-linq-to-sql-part-4-of-n/</link>
		<comments>http://randolphcabral.wordpress.com/2008/05/21/exploring-n-tier-architecture-with-linq-to-sql-part-4-of-n/#comments</comments>
		<pubDate>Wed, 21 May 2008 17:33:43 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=24</guid>
		<description><![CDATA[Sanity Check Now that we&#8217;ve completed the first of what I&#8217;m sure will be many coding iterations of our business entity layer solution it is now time to do some testing.  In this post we&#8217;ll take some time to make sure our approach holds up to a typical usage scenario.  To do this, I&#8217;ve put [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=24&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Sanity Check</strong></p>
<p>Now that we&#8217;ve completed the first of what I&#8217;m sure will be many coding iterations of our business entity layer solution it is now time to do some testing.  In this post we&#8217;ll take some time to make sure our approach holds up to a typical usage scenario.  To do this, I&#8217;ve put together a Visual Studio solution that contains a web application and a couple of class libraries.  One class library for our LINQ to SQL entities and another for our business entities.  We&#8217;ll attempt to build out the domain model and use it in our web UI layer to demonstrate how we could interact with the business entities.</p>
<p><img src="http://randolphcabral.files.wordpress.com/2008/05/solutionexplorer.jpg" alt="" /></p>
<p>Let&#8217;s start with the LINQ to SQL class library project.  In this project we have Northwind.dbml, Northwind.dbml.layout, and Northwind.designer.cs files.  The files and its contents were generated by the Visual Studio 2008 IDE using SQLMetal after I dragged the Customer, Order, Order_Detail, and Product tables on to the design surface from the Server Explorer.  I&#8217;ve taken a screen shot of the resulting diagram from the designer (below).  Each box represents a table in the database which in turn is generated into a corresponding LINQ to SQL class complete with mappings and a DataContext.</p>
<p><a href="http://randolphcabral.files.wordpress.com/2008/05/dmbldesigner.jpg"></a> <img src="http://randolphcabral.files.wordpress.com/2008/05/dmbldesigner.jpg" alt="" /></p>
<p><strong>Business Context</strong></p>
<p>Moving over to the business entity project, I&#8217;ve written a class for each LINQ to SQL entity as well as a business context class that wraps the DataContext class.  The following code sample implements the business context (in its entirety) in much the same way we explored in <a href="http://randolphcabral.wordpress.com/2008/04/24/exploring-n-tier-architecture-with-linq-to-sql-part-2-of-n/">Part 2</a> of this series.  An item to note is the addition of two methods that handle attachment of disconnected entities for inserting and deleting at lines 97 and 108 respectively.  In order to support all business entity types, we use reflection to find the LinqEntity member and use the composed DataContext to invoke data store logic.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    1</span>   <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">NorthwindBusinessContext</span> : <span style="color:#2b91af;">IDisposable</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    2</span>   {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    3</span>     <span style="color:#0000ff;">public</span> NorthwindBusinessContext()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    4</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    5</span>       DataContext = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">NorthwindDataContext</span>();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    6</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    7</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    8</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">PersistStateEvent</span> OnBeforePersistState;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    9</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">event</span> <span style="color:#2b91af;">PersistStateEvent</span> OnAfterPersistState;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   10</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   11</span>     <span style="color:#0000ff;">protected</span> <span style="color:#2b91af;">NorthwindDataContext</span> DataContext { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   12</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   13</span> <span style="color:#0000ff;">    #region</span> Factory Methods</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   14</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   15</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">CustomerBus</span> GetCustomerBusBy(<span style="color:#0000ff;">string</span> customerID)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   16</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   17</span>       <span style="color:#0000ff;">var</span> linqEntity = DataContext.GetTable&lt;<span style="color:#2b91af;">Customer</span>&gt;()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   18</span>         .Single(entity =&gt; entity.CustomerID == customerID);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   19</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">CustomerBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   20</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   21</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   22</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   23</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">CustomerBus</span>&gt; GetAllCustomerBuses()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   24</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   25</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Collection</span>&lt;<span style="color:#2b91af;">CustomerBus</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   26</span>       <span style="color:#0000ff;">var</span> result = DataContext.GetTable&lt;<span style="color:#2b91af;">Customer</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   27</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> linqEntity <span style="color:#0000ff;">in</span> result)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   28</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   29</span>         <span style="color:#0000ff;">var</span> entity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">CustomerBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   30</span>         ret.Add(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   31</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   32</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   33</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   34</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   35</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">OrderBus</span> GetOrderBusBy(<span style="color:#0000ff;">int</span> orderID)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   36</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   37</span>       <span style="color:#0000ff;">var</span> linqEntity = DataContext.GetTable&lt;<span style="color:#2b91af;">Order</span>&gt;()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   38</span>         .Single(entity =&gt; entity.OrderID == orderID);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   39</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OrderBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   40</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   41</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   42</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   43</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">OrderBus</span>&gt; GetAllOrderBuses()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   44</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   45</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Collection</span>&lt;<span style="color:#2b91af;">OrderBus</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   46</span>       <span style="color:#0000ff;">var</span> result = DataContext.GetTable&lt;<span style="color:#2b91af;">Order</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   47</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> linqEntity <span style="color:#0000ff;">in</span> result)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   48</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   49</span>         <span style="color:#0000ff;">var</span> entity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OrderBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   50</span>         ret.Add(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   51</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   52</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   53</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   54</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   55</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">Detail</span> GetDetailBy(<span style="color:#0000ff;">int</span> orderID, <span style="color:#0000ff;">int</span> productID)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   56</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   57</span>       <span style="color:#0000ff;">var</span> linqEntity = DataContext.GetTable&lt;<span style="color:#2b91af;">Order_Detail</span>&gt;()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   58</span>         .Single(entity =&gt; entity.OrderID == orderID &amp;&amp; entity.ProductID == productID);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   59</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Detail</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   60</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   61</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   62</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   63</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">Detail</span>&gt; GetAllDetails()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   64</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   65</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Collection</span>&lt;<span style="color:#2b91af;">Detail</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   66</span>       <span style="color:#0000ff;">var</span> result = DataContext.GetTable&lt;<span style="color:#2b91af;">Order_Detail</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   67</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> linqEntity <span style="color:#0000ff;">in</span> result)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   68</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   69</span>         <span style="color:#0000ff;">var</span> entity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Detail</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   70</span>         ret.Add(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   71</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   72</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   73</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   74</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   75</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">ProductBus</span> GetProductBusBy(<span style="color:#0000ff;">int</span> productID)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   76</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   77</span>       <span style="color:#0000ff;">var</span> linqEntity = DataContext.GetTable&lt;<span style="color:#2b91af;">Product</span>&gt;()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   78</span>         .Single(entity =&gt; entity.ProductID == productID);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   79</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ProductBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   80</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   81</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   82</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   83</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">IEnumerable</span>&lt;<span style="color:#2b91af;">ProductBus</span>&gt; GetAllProductBuses()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   84</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   85</span>       <span style="color:#0000ff;">var</span> ret = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Collection</span>&lt;<span style="color:#2b91af;">ProductBus</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   86</span>       <span style="color:#0000ff;">var</span> result = DataContext.GetTable&lt;<span style="color:#2b91af;">Product</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   87</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> linqEntity <span style="color:#0000ff;">in</span> result)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   88</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   89</span>         <span style="color:#0000ff;">var</span> entity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ProductBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   90</span>         ret.Add(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   91</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   92</span>       <span style="color:#0000ff;">return</span> ret;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   93</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   94</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   95</span> <span style="color:#0000ff;">    #endregion</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   96</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   97</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> DeleteOnPersistState(<span style="color:#0000ff;">object</span> entity)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   98</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   99</span>       <span style="color:#0000ff;">var</span> linqEntityRef = entity.GetType().GetProperty(<span style="color:#a31515;">&#8220;LinqEntity&#8221;</span>,</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  100</span>         System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.Instance</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  101</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.NonPublic</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  102</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.Public</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  103</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.FlattenHierarchy).GetValue(entity, <span style="color:#0000ff;">null</span>);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  104</span>       <span style="color:#0000ff;">var</span> linqEntityType = linqEntityRef.GetType();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  105</span>       DataContext.GetTable(linqEntityType).DeleteOnSubmit(linqEntityRef);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  106</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  107</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  108</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> AddOnPersistState(<span style="color:#0000ff;">object</span> entity)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  109</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  110</span>       <span style="color:#0000ff;">var</span> linqEntityRef = entity.GetType().GetProperty(<span style="color:#a31515;">&#8220;LinqEntity&#8221;</span>,</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  111</span>         System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.Instance</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  112</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.NonPublic</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  113</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.Public</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  114</span>         | System.Reflection.<span style="color:#2b91af;">BindingFlags</span>.FlattenHierarchy).GetValue(entity, <span style="color:#0000ff;">null</span>);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  115</span>       <span style="color:#0000ff;">var</span> linqEntityType = linqEntityRef.GetType();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  116</span>       DataContext.GetTable(linqEntityType).InsertOnSubmit(linqEntityRef);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  117</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  118</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  119</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> PersistState()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  120</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  121</span>       <span style="color:#0000ff;">if</span> (OnBeforePersistState != <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  122</span>         OnBeforePersistState(<span style="color:#0000ff;">this</span>, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EventArgs</span>());</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  123</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  124</span>       DataContext.SubmitChanges();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  125</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  126</span>       <span style="color:#0000ff;">if</span> (OnAfterPersistState != <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  127</span>         OnAfterPersistState(<span style="color:#0000ff;">this</span>, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EventArgs</span>());</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  128</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  129</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  130</span> <span style="color:#0000ff;">    #region</span> IDisposable Members</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  131</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  132</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Dispose()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  133</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  134</span>       DataContext.Dispose();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  135</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  136</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  137</span> <span style="color:#0000ff;">    #endregion</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  138</span>   }</p>
</div>
<p><!--EndFragment--> </p>
<p><strong>Business Entity</strong></p>
<p>Below is a sample of the CustomerBus business entity.  I&#8217;ve removed some of the properties and associations that implement the same pattern for brevity.  Each of the business classes implemented in this project employ the design constructs we explored in <a href="http://randolphcabral.wordpress.com/2008/05/08/exploring-n-tier-architecture-with-linq-to-sql-part-3-of-n/">Part 3</a> of this series.  Additionally, I&#8217;ve written an IValidateable interface and a SimpleDataValidator class that reads the custom attributes found on each public property and populates a collection of validation errors when any of the tests fail.  More on validation in a future post.  In this post we&#8217;ll focus on the business context and the business entities.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    1</span>   <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">CustomerBus</span> : <span style="color:#2b91af;">IEntity</span>, <span style="color:#2b91af;">IValidateable</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    2</span>   {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    3</span>     <span style="color:#0000ff;">public</span> CustomerBus()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    4</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    5</span>       Validators.Add(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">SimpleDataValidator</span>());</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    6</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    7</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    8</span>     <span style="color:#0000ff;">internal</span> CustomerBus(<span style="color:#2b91af;">Customer</span> linqEntity) : <span style="color:#0000ff;">this</span>()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    9</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   10</span>       LinqEntity = linqEntity;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   11</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   12</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   13</span>     <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">Customer</span> _linqEntity = <span style="color:#0000ff;">null</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   14</span>     <span style="color:#0000ff;">internal</span> <span style="color:#2b91af;">Customer</span> LinqEntity</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   15</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   16</span>       <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   17</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   18</span>         <span style="color:#0000ff;">if</span> (_linqEntity == <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   19</span>           _linqEntity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Customer</span>();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   20</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   21</span>         <span style="color:#0000ff;">return</span> _linqEntity;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   22</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   23</span>       <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   24</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   25</span>         _linqEntity = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   26</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   27</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   28</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   29</span> <span style="color:#0000ff;">    #region</span> Properties</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   30</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   31</span>     [<span style="color:#2b91af;">Required</span>(<span style="color:#a31515;">"'CustomerID' is a required field."</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   32</span>     [<span style="color:#2b91af;">MaxLength</span>(5, <span style="color:#a31515;">"The 'CustomerID' field cannot accept more than 5 characters."</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   33</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">string</span> CustomerID</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   34</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   35</span>       <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   36</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   37</span>         <span style="color:#0000ff;">return</span> LinqEntity.CustomerID;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   38</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   39</span>       <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   40</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   41</span>         LinqEntity.CustomerID = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   42</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   43</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   44</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   45</span>     [<span style="color:#2b91af;">Required</span>(<span style="color:#a31515;">"'CompanyName' is a required field."</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   46</span>     [<span style="color:#2b91af;">MaxLength</span>(40, <span style="color:#a31515;">"The 'CompanyName' field cannot accept more than 40 characters."</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   47</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">string</span> CompanyName</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   48</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   49</span>       <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   50</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   51</span>         <span style="color:#0000ff;">return</span> LinqEntity.CompanyName;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   52</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   53</span>       <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   54</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   55</span>         LinqEntity.CompanyName = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   56</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   57</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   58</span>     &#8230;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   59</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   60</span> <span style="color:#0000ff;">    #endregion</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   61</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   62</span> <span style="color:#0000ff;">    #region</span> Associations</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   63</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   64</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">void</span> AddOrderBus(<span style="color:#2b91af;">OrderBus</span> entity)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   65</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   66</span>       _Orders.Add(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   67</span>       LinqEntity.Orders.Add(entity.LinqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   68</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   69</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   70</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#0000ff;">void</span> RemoveOrderBus(<span style="color:#2b91af;">OrderBus</span> entity)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   71</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   72</span>       _Orders.Remove(entity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   73</span>       LinqEntity.Orders.Remove(entity.LinqEntity);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   74</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   75</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   76</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#2b91af;">OrderBusCollection</span> Orders</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   77</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   78</span>       <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   79</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   80</span>         <span style="color:#0000ff;">if</span> (_Orders == <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   81</span>           _Orders = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OrderBusCollection</span>(LinqEntity.Orders);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   82</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   83</span>         <span style="color:#0000ff;">return</span> _Orders;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   84</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   85</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   86</span>     <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">OrderBusCollection</span> _Orders = <span style="color:#0000ff;">null</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   87</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   88</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   89</span> <span style="color:#0000ff;">    #endregion</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   90</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   91</span> <span style="color:#0000ff;">    #region</span> IValidateable Members</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   92</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   93</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> ClearValidationErrors()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   94</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   95</span>       ValidationErrors.Clear();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   96</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   97</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   98</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">bool</span> HasValidationErrors</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   99</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  100</span>       <span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> (ValidationErrors.Count &gt; 0); }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  101</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  102</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  103</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidator</span>&gt; Validators</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  104</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  105</span>       <span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _validators; }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  106</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  107</span>     <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidator</span>&gt; _validators = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidator</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  108</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  109</span>     <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Validate()</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  110</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  111</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> v <span style="color:#0000ff;">in</span> Validators)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  112</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  113</span>         v.Validate(<span style="color:#0000ff;">this</span>);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  114</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  115</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  116</span>       <span style="color:#0000ff;">if</span> (HasValidationErrors)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  117</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  118</span>         <span style="color:#0000ff;">var</span> errorMessages = <span style="color:#0000ff;">string</span>.Empty;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  119</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  120</span>         <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> v <span style="color:#0000ff;">in</span> ValidationErrors)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  121</span>           errorMessages += <span style="color:#0000ff;">string</span>.Format(<span style="color:#a31515;">&#8220;{0}&#8221;</span>, v.GetValidationErrorMessage());</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  122</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  123</span>         <span style="color:#0000ff;">if</span> (ValidationErrorHandling == <span style="color:#2b91af;">ValidationErrorHandling</span>.ThrowException)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  124</span>           <span style="color:#0000ff;">throw</span> <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">ValidationException</span>(errorMessages);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  125</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  126</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  127</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  128</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">ValidationErrorHandling</span> ValidationErrorHandling</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  129</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  130</span>       <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  131</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  132</span>         <span style="color:#0000ff;">return</span> _validationErrorHandling;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  133</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  134</span>       <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  135</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  136</span>         _validationErrorHandling = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  137</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  138</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  139</span>     <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">ValidationErrorHandling</span> _validationErrorHandling = <span style="color:#2b91af;">ValidationErrorHandling</span>.ThrowException;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  140</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  141</span>     <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidationError</span>&gt; ValidationErrors</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  142</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  143</span>       <span style="color:#0000ff;">get</span> { <span style="color:#0000ff;">return</span> _validationErrors; }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  144</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  145</span>     <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidationError</span>&gt; _validationErrors = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IValidationError</span>&gt;();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  146</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  147</span> <span style="color:#0000ff;">    #endregion</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  148</span>   }</p>
</div>
<p><!--EndFragment--></p>
<p><strong></strong> </p>
<p><strong>Application Tier</strong> </p>
<p>In the web application, we have a web.config file and a Default.aspx with its code file Default.aspx.cs.  We won&#8217;t be making any modifications to the HTML markup in the Default.aspx file because in this test all we want to do is run some basic reads and updates on the data store.  To be able to use the classes we&#8217;ve defined in the business library project we&#8217;ll add a reference to the project.</p>
<p> <img src="http://randolphcabral.files.wordpress.com/2008/05/reference1.jpg" alt="" /></p>
<p>Now let&#8217;s take a look at the code written in the Page_Load() event handler.  Starting with line 10, we instantiate a business context object so that we can request a CustomerBus object with one of the factory methods.  We want to test the object tracking capabilities of the underlying DataContext so on line 12 we make sure the City property is updated.  To test the associations we loop through the Orders collection and modify the OrderDate property.  Taking this a step further, we do a similar operation and traverse the OrderDetails collection and update both quantity and price by incrementing each property.  Finally, a call to the PersistState() method completes this test.  Remember, each time we traverse the object graph&#8217;s entity associations, we incur a lazy-load query against the data store because such is the default behavior of LINQ to SQL.  You can easily modify this option by setting the DataContext DeferredLoadingEnabled property to false.  This won&#8217;t hurt our lazy-loading code in the business entity layer because the underlying DataContext will have preloaded the entities.  Our business entities will simply request the objects from the DataContext.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    1</span> <span style="color:#0000ff;">using</span> System;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    2</span> <span style="color:#0000ff;">using</span> Northwind.Entities;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    3</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    4</span> <span style="color:#0000ff;">namespace</span> L2SnTierTestWeb</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    5</span> {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    6</span>   <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">_Default</span> : System.Web.UI.<span style="color:#2b91af;">Page</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    7</span>   {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    8</span>     <span style="color:#0000ff;">protected</span> <span style="color:#0000ff;">void</span> Page_Load(<span style="color:#0000ff;">object</span> sender, <span style="color:#2b91af;">EventArgs</span> e)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    9</span>     {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   10</span>       <span style="color:#0000ff;">var</span> ctx = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">NorthwindBusinessContext</span>();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   11</span>       <span style="color:#0000ff;">var</span> cust = ctx.GetCustomerBusBy(<span style="color:#a31515;">&#8220;ALFKI&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   12</span>       cust.City = (cust.City == <span style="color:#a31515;">&#8220;Berlin&#8221;</span>) ? <span style="color:#a31515;">&#8220;Hamburg&#8221;</span> : <span style="color:#a31515;">&#8220;Berlin&#8221;</span>;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   13</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   14</span>       <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> order <span style="color:#0000ff;">in</span> cust.Orders)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   15</span>       {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   16</span>         order.OrderDate = <span style="color:#2b91af;">DateTime</span>.Now;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   17</span>         <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var</span> orderdetail <span style="color:#0000ff;">in</span> order.OrderDetails)</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   18</span>         {</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   19</span>           orderdetail.Quantity++;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   20</span>           orderdetail.Product.UnitPrice++;</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   21</span>         }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   22</span>       }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   23</span> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   24</span>       ctx.PersistState();</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   25</span>     }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   26</span>   }</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   27</span> }</p>
</div>
<p> </p>
<p><strong>SQL Profiler</strong></p>
<p>At this point we can open up SQL Profiler and inspect the resulting queries.  On the reads, we can see a total twenty of queries, one for the initial customer query and one for each lazy-loading relationship.  Again, if you want the object graph to preload, setting a property on the DataContext is all that is required.  On the update side, which starts at line 130, we are greated with a very nice set of batched updates that handle customers, orders, and details.   This is consistent with using LINQ to SQL out of the box.  Only now we&#8217;re working with our own business entities where we can add domain specific logic.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    1</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    2</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    3</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[CustomerID], [t0].[CompanyName], [t0].[ContactName], [t0].[ContactTitle], [t0].[Address], [t0].[City], [t0].[Region], [t0].[PostalCode], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    4</span> <span style="color:#a31515;">[t0].[Country], [t0].[Phone], [t0].[Fax]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    5</span> <span style="color:#a31515;">FROM [dbo].[Customers] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    6</span> <span style="color:#a31515;">WHERE [t0].[CustomerID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 nvarchar(5)&#8217;</span>, @p0 = N<span style="color:#a31515;">&#8216;ALFKI&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    7</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    8</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">    9</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   10</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[CustomerID], [t0].[EmployeeID], [t0].[OrderDate], [t0].[RequiredDate], [t0].[ShippedDate], [t0].[ShipVia], [t0].[Freight], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   11</span> <span style="color:#a31515;">[t0].[ShipName], [t0].[ShipAddress], [t0].[ShipCity], [t0].[ShipRegion], [t0].[ShipPostalCode], [t0].[ShipCountry]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   12</span> <span style="color:#a31515;">FROM [dbo].[Orders] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   13</span> <span style="color:#a31515;">WHERE [t0].[CustomerID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 nvarchar(5)&#8217;</span>, @p0 = N<span style="color:#a31515;">&#8216;ALFKI&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   14</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   15</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   16</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   17</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   18</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   19</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 10643</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   20</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   21</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   22</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   23</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   24</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   25</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   26</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 28</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   27</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   28</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   29</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   30</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   31</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   32</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   33</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 39</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   34</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   35</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   36</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   37</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   38</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   39</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   40</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 46</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   41</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   42</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   43</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   44</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   45</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   46</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 10692</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   47</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   48</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   49</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   50</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   51</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   52</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   53</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 63</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   54</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   55</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   56</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   57</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   58</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   59</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 10702</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   60</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   61</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   62</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   63</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   64</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   65</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   66</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 3</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   67</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   68</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   69</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   70</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   71</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   72</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   73</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 76</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   74</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   75</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   76</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   77</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   78</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   79</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 10835</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   80</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   81</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   82</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   83</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   84</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   85</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   86</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 59</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   87</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   88</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   89</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   90</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   91</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   92</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   93</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 77</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   94</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   95</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   96</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   97</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   98</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">   99</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 10952</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  100</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  101</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  102</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  103</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  104</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  105</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  106</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 6</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  107</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  108</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  109</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  110</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[OrderID], [t0].[ProductID], [t0].[UnitPrice], [t0].[Quantity], [t0].[Discount]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  111</span> <span style="color:#a31515;">FROM [dbo].[Order Details] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  112</span> <span style="color:#a31515;">WHERE [t0].[OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 11011</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  113</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  114</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  115</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  116</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  117</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  118</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  119</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 58</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  120</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  121</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  122</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  123</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;SELECT [t0].[ProductID], [t0].[ProductName], [t0].[SupplierID], [t0].[CategoryID], [t0].[QuantityPerUnit], [t0].[UnitPrice], [t0].[UnitsInStock], </span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  124</span> <span style="color:#a31515;">[t0].[UnitsOnOrder], [t0].[ReorderLevel], [t0].[Discontinued]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  125</span> <span style="color:#a31515;">FROM [dbo].[Products] AS [t0]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  126</span> <span style="color:#a31515;">WHERE [t0].[ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int&#8217;</span>, @p0 = 71</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  127</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  128</span> <span style="color:#0000ff;">exec </span>sp_reset_connection</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  129</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  130</span> <span style="color:#0000ff;">SET TRANSACTION ISOLATION LEVEL READ COMMITTED</span>;<span style="color:#0000ff;">BEGIN TRANSACTION</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  131</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  132</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Customers]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  133</span> <span style="color:#a31515;">SET [City] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  134</span> <span style="color:#a31515;">WHERE [CustomerID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 nchar(5),@p1 nvarchar(6)&#8217;</span>, @p0 = N<span style="color:#a31515;">&#8216;ALFKI&#8217;</span>, @p1 = N<span style="color:#a31515;">&#8216;Berlin&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  135</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  136</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  137</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  138</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 10643, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:667AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  139</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  140</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  141</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  142</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 10692, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:677AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  143</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  144</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  145</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  146</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 10702, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:680AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  147</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  148</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  149</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  150</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 10835, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:687AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  151</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  152</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  153</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  154</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 10952, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:693AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  155</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  156</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Orders]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  157</span> <span style="color:#a31515;">SET [OrderDate] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  158</span> <span style="color:#a31515;">WHERE [OrderID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 datetime&#8217;</span>, @p0 = 11011, @p1 = <span style="color:#a31515;">&#8216;May 21 2008 12:28:08:697AM&#8217;</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  159</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  160</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  161</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  162</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10643, @p1 = 28, @p2 = 28</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  163</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  164</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  165</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  166</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10643, @p1 = 39, @p2 = 34</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  167</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  168</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  169</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  170</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10643, @p1 = 46, @p2 = 15</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  171</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  172</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  173</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  174</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10692, @p1 = 63, @p2 = 33</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  175</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  176</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  177</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  178</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10702, @p1 = 3, @p2 = 19</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  179</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  180</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  181</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  182</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10702, @p1 = 76, @p2 = 28</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  183</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  184</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  185</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  186</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10835, @p1 = 59, @p2 = 28</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  187</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  188</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  189</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  190</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10835, @p1 = 77, @p2 = 15</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  191</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  192</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  193</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  194</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10952, @p1 = 6, @p2 = 29</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  195</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  196</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  197</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  198</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 10952, @p1 = 28, @p2 = 15</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  199</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  200</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  201</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  202</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 11011, @p1 = 58, @p2 = 53</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  203</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  204</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Order Details]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  205</span> <span style="color:#a31515;">SET [Quantity] = @p2</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  206</span> <span style="color:#a31515;">WHERE ([OrderID] = @p0) AND ([ProductID] = @p1)&#8217;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 int,@p2 smallint&#8217;</span>, @p0 = 11011, @p1 = 71, @p2 = 33</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  207</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  208</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  209</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  210</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 3, @p1 = $19.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  211</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  212</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  213</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  214</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 6, @p1 = $34.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  215</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  216</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  217</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  218</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 28, @p1 = $63.6000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  219</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  220</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  221</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  222</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 39, @p1 = $27.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  223</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  224</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  225</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  226</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 46, @p1 = $21.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  227</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  228</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  229</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  230</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 58, @p1 = $22.2500</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  231</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  232</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  233</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  234</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 59, @p1 = $64.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  235</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  236</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  237</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  238</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 63, @p1 = $52.9000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  239</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  240</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  241</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  242</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 71, @p1 = $30.5000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  243</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  244</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  245</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  246</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 76, @p1 = $27.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  247</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  248</span> <span style="color:#0000ff;">exec </span>sp_executesql N<span style="color:#a31515;">&#8216;UPDATE [dbo].[Products]</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  249</span> <span style="color:#a31515;">SET [UnitPrice] = @p1</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  250</span> <span style="color:#a31515;">WHERE [ProductID] = @p0&#8242;</span>, N<span style="color:#a31515;">&#8216;@p0 int,@p1 money&#8217;</span>, @p0 = 77, @p1 = $22.0000</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  251</span> go</p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  252</span> <span style="color:#0000ff;">COMMIT TRANSACTION</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">  253</span> go</p>
</div>
<p> </p>
<p>Sorry for the long post.  I&#8217;ll try to break it up more next time.  The take away here is that our efforts to abstract away the LINQ to SQL entities and DataContext have been successful so far.  I didn&#8217;t want to get too wrapped up in the minutia, but for those of you who absolutely need to loosen the coupling between the business layer from the LINQ to SQL layer I would recommend extracting the interface out of each of the LINQ to SQL entities and its DataContext.  This would allow for the flexibility of dependency injection (interface injection in this case) and TDD at the business layer.  Keep in mind that at some point the benefits of this loose coupling versus the return may start to diminish depending on your project.  I&#8217;ll let you decide what&#8217;s best for your project.</p>
<p>In the next part of this series, we&#8217;ll take a look at what we can do to finally marry the ActiveRecord pattern to our abstracted model.  I will concede that at this point, there may be no need to come full circle with AR.  I&#8217;m completely sold on the idea of using the Unit of Work pattern (context) in lieu of AR.  What I grappled with at first was this issue of trust.  I needed to trust the context and relinquish control.  The AR pattern gave me ultimate control of what DML operations were called and when they were executed on the data store.  As a developer, you&#8217;re going to need to develop a trusting relationship with the context.  Then and only then will you be able to embrace its liberating capabilities.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=24&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/05/21/exploring-n-tier-architecture-with-linq-to-sql-part-4-of-n/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>

		<media:content url="http://randolphcabral.files.wordpress.com/2008/05/solutionexplorer.jpg" medium="image" />

		<media:content url="http://randolphcabral.files.wordpress.com/2008/05/dmbldesigner.jpg" medium="image" />

		<media:content url="http://randolphcabral.files.wordpress.com/2008/05/reference1.jpg" medium="image" />
	</item>
		<item>
		<title>Exploring N-Tier Architecture with LINQ to SQL (Part 3 of n)</title>
		<link>http://randolphcabral.wordpress.com/2008/05/08/exploring-n-tier-architecture-with-linq-to-sql-part-3-of-n/</link>
		<comments>http://randolphcabral.wordpress.com/2008/05/08/exploring-n-tier-architecture-with-linq-to-sql-part-3-of-n/#comments</comments>
		<pubDate>Thu, 08 May 2008 16:42:30 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=23</guid>
		<description><![CDATA[Part 3 - Creating Business Entities from Data Entities In part one of this series we looked at how LINQ to SQL entities are structured by analyzing its members and mappings.  We concluded that that they aren&#8217;t suitable in a model where we would derive from them because doing so would hide the LINQ to SQL mappings from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=23&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Part 3 - Creating Business Entities from Data Entities</strong></p>
<p>In <a href="http://randolphcabral.wordpress.com/2008/04/23/exploring-n-tier-architecture-with-linq-to-sql-part-1-of-n/">part one</a> of this series we looked at how LINQ to SQL entities are structured by analyzing its members and mappings.  We concluded that that they aren&#8217;t suitable in a model where we would derive from them because doing so would hide the LINQ to SQL mappings from the query provider.  Creating a translation layer to handle loading and tracking of business entites would be too monumental a task to take on.   Clearly that&#8217;s not an option either.  Ideally, we want to encapsulate the data entities in business entities without sacrificing code re-usability.  Fortunately, we have a neat pattern that we can use to do just that and it&#8217;s called object composition.</p>
<p>Do the names Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides ring a bell?  Do you know what I&#8217;m referring to when I say, &#8220;GoF&#8221;?  Yes, you guessed it.  The Gang of Four and their book, <em><a href="http://en.wikipedia.org/wiki/Design_Patterns">Design Patterns: Elements of Reusable Object-Oriented Software</a>.</em>  In the book, they cite several important design techniques such as programming to an interface and object composition.  The one we&#8217;re interested in right now is object composition.  Take for example a business requirement where every customer record must have address data for billing and shipping.  Because the requirements for the Customer object only require a couple of addresses we can model the relationship with object composition using an Address class.  The code sample below illustrates how we would write the Customer class using this pattern.  Notice that there are two public Address properties which represent billing and shipping data as separate object instances.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Address</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> Street { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string</span> City { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string </span>PostalCode { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;">}</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Customer</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">Address </span>BillingAddress { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">Address </span>ShippingAddress { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p><!--EndFragment-->With a little tweaking, we should be able to apply this pattern to reuse the LINQ to SQL entities within our business classes.  In the following code sample, we start by writing a business layer customer class called CustomerBus with an internal constructor that accepts a LINQ to SQL entity reference.  A private member that composes the LINQ to SQL Customer class keeps the reference in a safe place.  Now here&#8217;s where we deviate a little from the composition pattern.  Rather than adding a public property to expose the LINQ to SQL class, we&#8217;ll add public properties that expose each of the LINQ to SQL entity properties instead.  Doing this gives us more granular control in dealing with the data entity properties.  For example, we can change the names of the exposed properties, hide certain properties, and create custom domain specific validation logic for those properties we choose to expose.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//Business class</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">CustomerBus</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Internal constructor that accepts LINQ entity reference.</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">internal </span>CustomerBus(<span style="color:#2b91af;">Customer </span>linqEntity)</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    LinqEntity = linqEntity;</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Private LINQ entity reference</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">private </span><span style="color:#2b91af;">Customer </span>LinqEntity { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Sample property that exposes a LINQ entity property</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string </span>CustomerID</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#008000;">//Expose the LINQ entity property</span></p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">return </span>LinqEntity.CustomerID;</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#008000;">//Add domain specific validation logic here if desired.</span></p>
<p style="padding-left:10px;margin:0;">      LinqEntity.CustomerID = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  &#8230;</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p> </p>
<p><strong>Associations</strong><!--EndFragment--></p>
<p>Let&#8217;s take a look at how we would create relationships using this model.  One advantage of keeping a reference to the LINQ to SQL entity is that we have access to the relationships in the data layer.  Remember, our business entities can be constructed with the LINQ to SQL entities passed in as an argument to the internal constructor.  We can use the existing relationships created by LINQ to SQL in the data layer for free.  Our job just got a lot easier because all we need to worry about now is promoting the LINQ to SQL entity to a business entity.  Subsequently, we&#8217;re going to need to expose the LINQ to SQL entity member by declaring the property as &#8220;internal&#8221;.  This exposes the member to the other business entities in the assembly safely.  We&#8217;ll need this so we can read the LINQ to SQL entity to customize the add and remove logic in our collections.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//Business class</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">CustomerBus</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Changed from private to internal. </span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//And added custom getter and setter</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//LINQ entity reference</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">Customer </span>_linqEntity = <span style="color:#0000ff;">null</span>;</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">internal</span> <span style="color:#2b91af;">Customer </span>LinqEntity</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">if</span>(_linqEntity == <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;">        _linqEntity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Customer</span>();</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">return </span>_linqEntity;</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      _linqEntity = <span style="color:#0000ff;">value</span>;</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  &#8230;</p>
</div>
<p><!--EndFragment--><!--EndFragment--><!--EndFragment--><!--EndFragment-->Simply exposing the EntitySet&lt;T&gt; member from the data layer is not desirable in this case because that would expose the LINQ to SQL entities.  Support for customized add and remove logic to handle the EntitySet&lt;T&gt; reference requires a specialized collection class.  Our new collection class derives from System.Collections.ObjectModel.Collection&lt;T&gt; which implements many of the behaviors we need to manage the contained entities.  By deriving from Collection&lt;T&gt;, we get all of its functionality for free.  Next we can create a custom constructor that accepts the EntitySet&lt;T&gt; reference and declare it internal to the assembly.  We want to do this so that new collections of this type can only be instantiated from within this assembly to ensure that all instantiated objects are connected to a context.  The constructor will be responsible for promoting the LINQ to SQL entities to business entities and adding them to the collection.  Next we can add the specialized add and remove methods that hide the base class implementations to support management of the EntitySet&lt;T&gt; reference.  Now adds and removes are tracked by a context and can be processed as a batch.  Cool!</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//Specialized business collection for OrderBus class</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">OrderBusCollection</span> : <span style="color:#2b91af;">Collection</span>&lt;<span style="color:#2b91af;">OrderBus</span>&gt;</p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Internal constructor that uses the EntitySet&lt;T&gt; to hydrate itself</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">internal</span> OrderBusCollection(<span style="color:#2b91af;">EntitySet</span>&lt;<span style="color:#2b91af;">Order</span>&gt; entitySet)</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    EntitySet = entitySet;</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">foreach</span> (<span style="color:#0000ff;">var </span>linqEntity <span style="color:#0000ff;">in </span>EntitySet)</p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">var</span> entity = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OrderBus</span>(linqEntity);</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">base</span>.Add(entity);</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">EntitySet</span>&lt;<span style="color:#2b91af;">Order</span>&gt; EntitySet { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">set</span>; }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">void</span> Add(<span style="color:#2b91af;"><span style="color:#2b91af;">OrderBus </span></span>entity)</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    EntitySet.Add(entity.LinqEntity);</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">base</span>.Add(entity);</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">void</span> Remove(<span style="color:#2b91af;"><span style="color:#2b91af;">OrderBus </span></span>entity)</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    EntitySet.Remove(entity.LinqEntity);</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">base</span>.Remove(entity);</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">new</span> <span style="color:#0000ff;">void </span>RemoveAt(<span style="color:#0000ff;">int</span> index)</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    Remove(<span style="color:#0000ff;">this</span>[index]);</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p>At this point, we can add the custom collection members to the business class as seen in the following code sample.  The custom &#8220;lazy&#8221; getter implementation ensures that we load the collection once it is requested and keeps a reference to the instance for future reference.  Now we have a working model that deals with the LINQ to SQL entities behind the scenes allowing for presentation code to interact purely with business entities.  Additionally, we can implement business-specific logic in the business classes in the form of validations or custom behaviors.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//Business class</span></p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">CustomerBus</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#008000;">//Association to orders</span></p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">virtual</span> <span style="color:#2b91af;">OrderBusCollection</span> Orders</p>
<p style="padding-left:10px;margin:0;">  {</p>
<p style="padding-left:10px;margin:0;">    <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;">    {</p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">if</span> (_Orders == <span style="color:#0000ff;">null</span>)</p>
<p style="padding-left:10px;margin:0;">        _Orders = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">OrderBusCollection</span>(LinqEntity.Orders);</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">      <span style="color:#0000ff;">return</span> _Orders;</p>
<p style="padding-left:10px;margin:0;">    }</p>
<p style="padding-left:10px;margin:0;">  }</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#0000ff;">private</span> <span style="color:#2b91af;">OrderBusCollection</span> _Orders = <span style="color:#0000ff;">null</span>;</p>
<p style="padding-left:10px;margin:0;"> </p>
<p style="padding-left:10px;margin:0;">  &#8230;</p>
</div>
<p><!--EndFragment-->Yes, I know it&#8217;s lot of code to have to write by hand.  But this is one of those busy tasks that can clearly be remedied with a custom code generator.  I&#8217;m currently working on one that I will make available in a future post.  Until then, there will be a lot of code to write.  The result of writing the code is clear.  We&#8217;ve created a business entity layer that abstracts the data entities away and gives us a nice place to add domain logic.  Another point of consternation might be with the pervasive use of the LINQ to SQL entities in the business layer.  This is one case where I feel the benefit of having those entity references localized in each business class outweigh the challenges that might be introduced with changes in the data tier.  We can somewhat isolate those issues with a custom code generator which should take most of the pains away.  The code generator I&#8217;m working on declares each business class as a partial class.  This will allow us to keep our custom implementation separate from anything that was automatically generated by the code generator.</p>
<p>In the next post, we&#8217;ll revisit the BusinessContext class to give it functionality to attach newly constructed business objects.  We&#8217;ll also take a look at the result of our efforts so far with a sample web application that uses our new business layer and take a peek at SQL Profiler to check out how our changes impact LINQ to SQL&#8217;s query provider.<!--EndFragment--></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=23&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/05/08/exploring-n-tier-architecture-with-linq-to-sql-part-3-of-n/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>You&#8217;re Not A &#8220;Real Programmer&#8221;</title>
		<link>http://randolphcabral.wordpress.com/2008/04/30/youre-not-a-real-programmer/</link>
		<comments>http://randolphcabral.wordpress.com/2008/04/30/youre-not-a-real-programmer/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 08:49:14 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=22</guid>
		<description><![CDATA[I recently met up with a fellow programmer buddy of mine who has been working for a software development group that has gone through several managers recently.  Each manager, varying in both development and management experience, had varying ideas on how to approach the requirements for a specific project.  Frequent turn over in management continued to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=22&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently met up with a fellow programmer buddy of mine who has been working for a software development group that has gone through several managers recently.  Each manager, varying in both development and management experience, had varying ideas on how to approach the requirements for a specific project.  Frequent turn over in management continued to complicate things.  Eventually, they found a manager that was willing to stick it out.  Unfortunately, his management style doesn&#8217;t exactly create a creative environment where developers can thrive. </p>
<p><span>The group has been charged with converting an existing windows forms client application for the web.  After exhaustive research into which web technology platform they wanted to develop on the manager decided to go against the tide and force the group to implement the new web application in C++.  Any developer in the group who expressed a difference in opinion was quickly shut down with the manager hinting at the notion that &#8220;real programmers&#8221; code in C++.</span></p>
<p><span>I have no problem with C++, but given that the requirements call for a web application, I&#8217;m going to have to respectfully disagree.  And what&#8217;s wrong with managed code anyway?  I guess only those who know how to manage resources manually are &#8220;real programmers&#8221;.  Many successful enterprise applications, both for the web and for windows, are written in Java or C#.  There are plenty of open source web development frameworks written for Java that increase productivity incredibly.  Similarly, ASP.NET with C# creates a powerful way to <span>programatically</span> access HTML controls. </span></p>
<p>In other words, we have power tools now that help us with the construction process.  Don&#8217;t get me wrong, there&#8217;s still a valid and relevant use for the handsaw.  Building a house is not one of those uses.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=22&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/04/30/youre-not-a-real-programmer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring N-Tier Architecture with LINQ to SQL (Part 2 of n)</title>
		<link>http://randolphcabral.wordpress.com/2008/04/24/exploring-n-tier-architecture-with-linq-to-sql-part-2-of-n/</link>
		<comments>http://randolphcabral.wordpress.com/2008/04/24/exploring-n-tier-architecture-with-linq-to-sql-part-2-of-n/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 16:59:18 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[Active Record]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Unit of Work]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=21</guid>
		<description><![CDATA[Part 2 &#8211; The DataContext To get us started on the right foot, let&#8217;s take a quick look at what is needed to write a custom DataContext class.  What&#8217;s really remarkable about the sample code below is that it is complete.  Simply deriving from the System.Data.Linq.DataContext base class and providing a connection string gives us [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=21&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Part 2 &#8211; The DataContext</strong></p>
<p>To get us started on the right foot, let&#8217;s take a quick look at what is needed to write a custom DataContext class.  What&#8217;s really remarkable about the sample code below is that it is complete.  Simply deriving from the System.Data.Linq.DataContext base class and providing a connection string gives us all of the functionality we need to work effectively with the data entities and the data source.  Obviously, the connection string should be abstracted into a configuration file and read in.  The code below was written this way to illustrate how easy it is to create a custom context for your project.  In our case, we&#8217;ll use the IDE and SQLMetal to generate our DataContext class which adds properties to expose each table dragged onto the designer surface.  The important thing to remember is that the GetTable&lt;TEntity&gt;() method is exposed as a public member which I will use in my samples to illustrate its IQueryable&lt;T&gt; properties.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="margin:0;">  <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">NorthwindDataContext</span>: System.Data.Linq.<span style="color:#2b91af;">DataContext</span></p>
<p style="margin:0;">  {</p>
<p style="margin:0;">    <span style="color:#0000ff;">public</span> MyDataContext()</p>
<p style="margin:0;">      : <span style="color:#0000ff;">base</span>(<span style="color:#a31515;">&#8220;Data Source=.;Initial Catalog=Northwind;Integrated Security=True&#8221;</span>)</p>
<p style="margin:0;">    {</p>
<p style="margin:0;">    }</p>
<p style="margin:0;">  }</p>
</div>
<p><!--EndFragment-->LINQ to SQL&#8217;s DataContext is both a blessing and a curse all at once.  I say this because it gives us a lot of out-of-the-box functionality with object state tracking and identity mapping, but it creates a problem when we want to separate the data layer from the business logic layer.  Imagine a typical business case where the properties of a business object are updated and then persisted to the data store.  Using an Active Record implementation, the instance of the object is created with a static factory method.  After modifying the object properties, a call to the Save() method is all that is needed to persist the state to the data store.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#2b91af;">Customer </span>cust = <span style="color:#2b91af;">Customer</span>.GetByCustomerId(<span style="color:#a31515;">&#8220;ALFKI&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;">cust.City = <span style="color:#a31515;">&#8220;Frankfurt&#8221;</span>;</p>
<p style="padding-left:10px;margin:0;">cust.Save();</p>
</div>
<p>Using LINQ to SQL&#8217;s DataContext, the pattern changes quite a bit.  Instead of a call to the static factory method on the class, as with the previous example, the entry point to retrieve an object instance changes to the DataContext.  Since there is no Save() method defined for the class, a call to SubmitChanges() on the DataContext is needed to invoke persistence logic. </p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">using</span> (<span style="color:#2b91af;">NorthwindDataContext </span>ctx = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">NorthwindDataContext</span>())</p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">  <span style="color:#2b91af;">Customer </span>cust = ctx.GetTable&lt;<span style="color:#2b91af;">Customer</span>&gt;().Single(c =&gt; c.CustomerID == <span style="color:#a31515;">&#8220;ALFKI&#8221;</span>);</p>
<p style="padding-left:10px;margin:0;">  cust.City = <span style="color:#a31515;">&#8220;Frankfurt&#8221;</span>;</p>
<p style="padding-left:10px;margin:0;">  ctx.SubmitChanges();</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p>Obviously, the Active Record implementation is concise and far easier to read when compared with the DataContext sample.  But that&#8217;s barely scratching the surface of potential issues.  Most troubling to me is that the DataContext object is now referenced in the business layer creating a strong coupling of the data and business layers.  How do we elegantly manage the DataContext without making it a first-class citizen in the business layer?  There are many different ways to approach this problem.  One way would be to wrap the context in a context manager utility class that exposes a method to load a customer entity by key.  Let&#8217;s call this class the NorthwindBusinessContext.  With the NorthwindBusinessContext class we could manage the lifecycle of a given context by implementing the IDisposable interface.  We can also ensure the integrity of context references to table entities that the DataContext exposes as shown with the GetCustomerById() method.  Lastly, the PersistState() method exposes the persistence method of the DataContext object which is, of course, necessary to invoke data store persistence logic. </p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:Courier New;">
<p style="margin:0;">  <span style="color:#0000ff;"><span style="color:#0000ff;">public</span><span style="color:#000000;"> <span style="color:#0000ff;">partial </span></span></span><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">NorthwindBusinessContext</span> : <span style="color:#2b91af;">IDisposable</span></p>
<p style="margin:0;">  {</p>
<p style="margin:0;">    <span style="color:#2b91af;">NorthwindDataContext </span>DataContext = <span style="color:#0000ff;">null</span>;</p>
<p style="margin:0;"> </p>
<p style="margin:0;">    <span style="color:#0000ff;">public</span> NorthwindBusinessContext()</p>
<p style="margin:0;">    {</p>
<p style="margin:0;">      DataContext = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">NorthwindDataContext</span>();</p>
<p style="margin:0;">    }</p>
<p style="margin:0;"> </p>
<p style="margin:0;">    <span style="color:#0000ff;">public</span> <span style="color:#2b91af;">Customer</span> GetCustomerById(<span style="color:#0000ff;">string </span>customerId)</p>
<p style="margin:0;">    {</p>
<p style="margin:0;">      <span style="color:#0000ff;">return </span>DataContext.GetTable&lt;<span style="color:#2b91af;">Customer</span>&gt;().Single(c =&gt; c.CustomerID == customerId);</p>
<p style="margin:0;">    }</p>
<p style="margin:0;"> </p>
<p style="margin:0;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void </span>PersistState()</p>
<p style="margin:0;">    {</p>
<p style="margin:0;">      DataContext.SubmitChanges();</p>
<p style="margin:0;">    }</p>
<p style="margin:0;"> </p>
<p style="margin:0;"><span style="color:#0000ff;">    #region </span>IDisposable Members</p>
<p style="margin:0;"> </p>
<p style="margin:0;">    <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> Dispose()</p>
<p style="margin:0;">    {</p>
<p style="margin:0;">      DataContext.Dispose();</p>
<p style="margin:0;">    }</p>
<p style="margin:0;"> </p>
<p style="margin:0;"><span style="color:#0000ff;">    #endregion</span></p>
<p style="margin:0;">  }</p>
</div>
<p><!--EndFragment--></p>
<p style="margin:0;">There has been some talk about how to scope the DataContext to a specific thread/web request/execution context to help ensure the integrity of the given DataContext.  I think there is a lot of merit in researching how to scope a given DataContext, however, I will not be exploring those efforts in this post.  We&#8217;ll leave that topic for another post, perhaps in the near future.</p>
<p style="margin:0;"> </p>
<p style="margin:0;">So why go to all this trouble of writing a BusinessContext?  Why not just use the DataContext outright and skip this step?  The answer: decoupling.  By encapsulating the DataContext in a single class, we can shield ourselves from any changes that are made to the DataContext implementation.  No one can argue that a single point of failure is a lot easier to refactor than a pervasive failure.  Things are looking good so far.  We have a BusinessContext class that composes the DataContext class and encapsulates DataContext specific implementation by implementing business specific methods for loading and persisting data entities.  Luckily, all this code is not to bad to write and can easily be incorporated to a custom code generator allowing us to write only the customizations needed by the domain layer.</p>
<p style="margin:0;"> </p>
<p style="margin:0;">Now all we have left is to deal with those data entities.  We want to deal with business entities, not data entities.  How do we best create a business entity that best allows for reuse of the data entities?  In my next post we&#8217;ll explore options on how to tackle this task in a fun an arguably elegant way.</p>
<p> </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=21&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/04/24/exploring-n-tier-architecture-with-linq-to-sql-part-2-of-n/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Exploring N-Tier Architecture with LINQ to SQL (Part 1 of n)</title>
		<link>http://randolphcabral.wordpress.com/2008/04/23/exploring-n-tier-architecture-with-linq-to-sql-part-1-of-n/</link>
		<comments>http://randolphcabral.wordpress.com/2008/04/23/exploring-n-tier-architecture-with-linq-to-sql-part-1-of-n/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 02:37:06 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[Active Record]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[Jammer.NET]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[POCO]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Unit of Work]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=16</guid>
		<description><![CDATA[Part 1 &#8211; Analyzing LINQ to SQL Entities For the past six months or so I&#8217;ve been playing a lot with LINQ to SQL to dissect and examine the internals of what makes it tick.&#160; It didn&#8217;t take long before I became a fan of LINQ to SQL, expression trees and IQueryable&#60;T&#62;.&#160; Those guys at [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=16&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Part 1 &#8211; Analyzing LINQ to SQL Entities</strong></p>
<p>For the past six months or so I&#8217;ve been playing a lot with LINQ to SQL to dissect and examine the internals of what makes it tick.&nbsp; It didn&#8217;t take long before I became a fan of LINQ to SQL, expression trees and IQueryable&lt;T&gt;.&nbsp; Those guys at Microsoft have really hit the nail on the head with this stuff.&nbsp; I started writing lots of LINQ to SQL code, debugging and watching SQL Profiler.&nbsp; I had a blast trying to find ways to break it.&nbsp; For the most part, it did really well in producing accurate, not always concise, SQL statements; albeit some queries could stand to be refactored.&nbsp; Regardless, LINQ to SQL delivers beyond my expectations.&nbsp; This is the point where I started to look for an elegant way to integrate LINQ to SQL with a classic N-Tier architecture.&nbsp; Unknowingly, I took the &#8220;red pill&#8221; and I dove head first into the rabbit hole.&nbsp; &#8220;How hard can this be?&#8221;, I thought to myself.</p>
<p>In my <a href="http://randolphcabral.wordpress.com/2008/04/03/active-record-vs-unit-of-work/" target="_blank">previous post</a>, I compared the relative merits and challenges of the Active Record pattern with the Unit of Work pattern.&nbsp; The Active Record pattern, in my opinion, creates a natural coding paradigm where business objects expose persistence behaviors as public methods.&nbsp; The challenge being that Active Record implementations ranging from Ruby to Subsonic to Jammer.NET have had issues with cardinality.&nbsp; Since most Active Record implementations do not implement the Identity Map pattern, lazy loading relationships in the object graph could create an infinite loop condition when recursive persistence logic is invoked.&nbsp; LINQ to SQL avoids these types of issues by implementing the Unit of Work pattern through its DataContext class.&nbsp; Because the DataContext tracks object state, persistence calls are batched with only those objects that need to be updated and there would be no need to traverse the object graph.&nbsp; A challenge with the DataContext lies with cases where the objects become disconnected from the DataContext.&nbsp; Another potential issue with the DataContext, in my opinion, is code clutter.&nbsp; I personally don&#8217;t like having logic to re-attach disconnected objects to the context cluttering up my code.</p>
<p>Weighing both patterns and considering their benefits and disadvantages, I decided to try an experiment to marry the two patterns.&nbsp; The Active Record persistence behaviors can encapsulate the logic required for re-attaching and, in turn, the Unit of Work container can handle tracking of object state and persistence.&nbsp; The only thing missing is the minister and a prenup to make it official.&nbsp; So off I go to try my hand at match-making.</p>
<p>Let&#8217;s inspect the entity class that was generated by LINQ to SQL&#8217;s code generator (SQLMetal).&nbsp; Firstly, as seen in the following code sample, each generated class is adorned with a TableAttribute to create a mapping to the database table.&nbsp; Additionally, the class is declared partial to allow for customizations to be kept in a separate file.&nbsp; This is nice, but falls short for our desire to create a business layer on top of these data entities.&nbsp; The class then implements a couple of interfaces from the System.ComponentModel namespace to support notification of property changes.&nbsp; It is really nice that it doesn&#8217;t need to derive from a concrete class as this gives us the opportunity to create a custom base class that all entities can derive from should we choose to do so.&nbsp; Unfortunately, the class is not adorned with the SerializableAttribute.&nbsp; The designer allows you to control the &#8220;Serialization Mode&#8221;, but this does not do what I was expecting it to do.&nbsp; Setting this property to &#8220;Unidirectional&#8221; causes the properties of the data entities to get adorned with a DataMemberAttribute which is a WCF XML serialization method.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//LINQ to SQL&#8217;s mapping attribute implementation</span></p>
<p style="padding-left:10px;margin:0;">[<span style="color:#2b91af;">Table</span>(Name=<span style="color:#a31515;">"dbo.Customers"</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">partial</span> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Customer</span> : <span style="color:#2b91af;">INotifyPropertyChanging</span>, <span style="color:#2b91af;">INotifyPropertyChanged</span></p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">&nbsp; &#8230;</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p><!--EndFragment--></p>
<p>Looking further in the class I found the public property mapping implementation.&nbsp; I was surprised to find its mapping attributes were adorned to the public properties (below).&nbsp;&nbsp; I was surprised because this meant that I could hide the mapping by simply deriving from the class and declaring a new property with the same name.&nbsp; What about polymorphism? I know what you&#8217;re thinking, this is supposed to be a data entity not a domain entity.&nbsp; I agree.&nbsp; However, I&#8217;m a believer in code reuse.&nbsp; If the data model entities closely match the domain model, why not derive from those entities to maximize code reuse?&nbsp; Furthermore, your domain entities can completely encapsulate domain logic from the data entity without having to model yet another class that implements all of the same properties.&nbsp; In other words, you get all of the data without all of the work for free.&nbsp; All that&#8217;s left to do is to write the business logic in a class that elegantly holds only business layer implementation.&nbsp; So naturally, I was surprised to see the mapping made at the property.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#008000;">//LINQ to SQL&#8217;s mapping attribute implementation</span></p>
<p style="padding-left:10px;margin:0;">[<span style="color:#2b91af;">Column</span>(Storage = <span style="color:#a31515;">"_CompanyName"</span>, DbType = <span style="color:#a31515;">"NVarChar(40) NOT NULL"</span>, CanBeNull = <span style="color:#0000ff;">false</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">string </span>CompanyName</p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">&nbsp; <span style="color:#0000ff;">get</span> { &#8230; }</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p>I later realized that LINQ to SQL deliberately creates mappings this way in order to support deferred execution.&nbsp; Because the public property is the referenced member of the class in the expression tree, a simple reflection call is all that is needed to retrieve the attribute instance.&nbsp; Formatting a SQL command statement becomes possible this way and is, indeed, a very nifty way of storing schema details without the need for an external mapping file (as found with the Hibernate mapping paradigm).&nbsp; I prefer having an inline attribute-based approach to Hibernate&#8217;s XML-based mapping files.&nbsp; I&#8217;ve always felt that having the mapping definitions inline with code was a cleaner way to implement mappings as the definitions are always only a click or two away.&nbsp; However, I do recognize the simplicity and elegance of an external mapping file as well as having the ability to cache the map in memory for performance.</p>
<p>As a quick test, I tried to derive from the LINQ to SQL entity and run a query from the context with out success.&nbsp; The reflection call that discovers the mapping attribute does not flatten the hierarchy and can&#8217;t retrieve the base property reference.&nbsp; Bummer.&nbsp; Microsoft, if you&#8217;re reading this, please modify the GetProperty() method call to include a binding flag value of &#8220;BindingFlags.FlattenHierarchy&#8221;.&nbsp; I think it would be really cool to have business objects that derive from data objects that are context connected.&nbsp; Maybe the answer is to wait for the ADO.NET Entity Framework for this type of support.</p>
<p>Next, we find the associations section.&nbsp; This is where relationships to other entities are made.&nbsp; Here we are introduced to the AssociationAttribute and the EntitySet&lt;T&gt; object.&nbsp; The EntitySet&lt;T&gt; came as a surprise to me because I was expecting a simple Collection&lt;T&gt; or even simpler, an array of Order objects to handle relationships.&nbsp; According to the MSDN documentation for EntitySet&lt;T&gt;, it provides deferred loading and relationship maintenance for the one-to-one and one-to-many collection relationships for LINQ to SQL applications.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;">[<span style="color:#2b91af;">Association</span>(Name=<span style="color:#a31515;">"Customer_Order"</span>, Storage=<span style="color:#a31515;">"_Orders"</span>, OtherKey=<span style="color:#a31515;">"CustomerID"</span>)]</p>
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> <span style="color:#2b91af;">EntitySet</span>&lt;<span style="color:#2b91af;">Order</span>&gt; Orders</p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">&nbsp; <span style="color:#0000ff;">get</span></p>
<p style="padding-left:10px;margin:0;">&nbsp; {</p>
<p style="padding-left:10px;margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">this</span>._Orders;</p>
<p style="padding-left:10px;margin:0;">&nbsp; }</p>
<p style="padding-left:10px;margin:0;">&nbsp; <span style="color:#0000ff;">set</span></p>
<p style="padding-left:10px;margin:0;">&nbsp; {</p>
<p style="padding-left:10px;margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#0000ff;">this</span>._Orders.Assign(<span style="color:#0000ff;">value</span>);</p>
<p style="padding-left:10px;margin:0;">&nbsp; }</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p><!--EndFragment--></p>
<p>Another relationship object that is found in the generated code is the EntityRef&lt;T&gt; class.&nbsp; Again, for deferred loading purposes a specialized class is used to handle direct parent relationships.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">private</span> <span style="color:#2b91af;">EntityRef</span>&lt;<span style="color:#2b91af;">Customer</span>&gt; _Customer;</p>
</div>
<p>How do these references get instantiated? Well, with the constructor of course! Yeah, I was confused at first too.&nbsp; The concept to note here is that the EntitySet&lt;T&gt; object is instantiated but not the actual entity until the Entity property is requested.&nbsp; I&#8217;m not sure what to think of this one.&nbsp; I&#8217;m guessing they wanted to push the responsibility of tracking when a related entity has been requested to another class in an effort to keep things clean with the entity class implementation.&nbsp; Certainly, this could have been achieved by adding more properties to the class.</p>
<div style="border-right:black 1px solid;border-top:black 1px solid;font-size:9pt;background:#dfdfdf;border-left:black 1px solid;color:black;border-bottom:black 1px solid;font-family:courier new;">
<p style="padding-left:10px;margin:0;"><span style="color:#0000ff;">public</span> Customer()</p>
<p style="padding-left:10px;margin:0;">{</p>
<p style="padding-left:10px;margin:0;">&nbsp; <span style="color:#0000ff;">this</span>._Orders = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">EntitySet</span>&lt;<span style="color:#2b91af;">Order</span>&gt;(<span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">Order</span>&gt;(<span style="color:#0000ff;">this</span>.attach_Orders), <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">Order</span>&gt;(<span style="color:#0000ff;">this</span>.detach_Orders));</p>
<p style="padding-left:10px;margin:0;">&nbsp; &#8230;</p>
<p style="padding-left:10px;margin:0;">}</p>
</div>
<p>So far so good.&nbsp; The entities generated by LINQ to SQL are relatively straight forward and relationships to other entities are handled relatively elegantly.&nbsp; The class does not derive from another concrete class and there is no data access logic to muddy up the waters.&nbsp; Inline attributes and the use of custom relationship classes make up the list of less desirable items, but shouldn&#8217;t impede our efforts to create an N-Tier architecture.&nbsp; Out of the box, LINQ to SQL provides an excellent way to quickly model a data layer with rich relationship structures.</p>
<p>In the next post, we&#8217;ll take a look at the DataContext class and evaluate how we could best take advantage of its object tracking capabilities.&nbsp; I&#8217;ll also explore writing a context manager class that helps ease the pains in dealing with the DataContext.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/16/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/16/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=16&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/04/23/exploring-n-tier-architecture-with-linq-to-sql-part-1-of-n/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>Active Record Vs. Unit of Work</title>
		<link>http://randolphcabral.wordpress.com/2008/04/03/active-record-vs-unit-of-work/</link>
		<comments>http://randolphcabral.wordpress.com/2008/04/03/active-record-vs-unit-of-work/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 02:42:51 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[Active Record]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Domain Model]]></category>
		<category><![CDATA[Jammer.NET]]></category>
		<category><![CDATA[LINQ to SQL]]></category>
		<category><![CDATA[Object Oriented Programming]]></category>
		<category><![CDATA[POCO]]></category>
		<category><![CDATA[Software Architecture]]></category>
		<category><![CDATA[Anemic Domain Model]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Unit of Work]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/?p=17</guid>
		<description><![CDATA[Lately, I&#8217;ve been doing some research on which path to take &#8211; Active Record or a pure Domain Model using the Unit of Work pattern.  Clearly there are advantages and disadvantages to both.  I&#8217;m hoping to find a good compromise between simplicity and flexibility.  When I say &#8216;simplicity&#8217;, I&#8217;m talking about the ever-elusive &#8216;elegant solution&#8217; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=17&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lately, I&#8217;ve been doing some research on which path to take &#8211; <a href="http://martinfowler.com/eaaCatalog/activeRecord.html" target="_blank">Active Record</a> or a pure <a href="http://martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Domain Model</a> using the <a href="http://martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank">Unit of Work</a> pattern.  Clearly there are advantages and disadvantages to both.  I&#8217;m hoping to find a good compromise between simplicity and flexibility.  When I say &#8216;simplicity&#8217;, I&#8217;m talking about the ever-elusive &#8216;elegant solution&#8217; where we are free from framework traps and <a href="http://martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">anemic domain models</a>.  As for &#8216;flexibility&#8217;, I&#8217;m referring to the ability to quickly change delivered functionality without having to rip apart the guts of the existing code base.  The thing that I keep getting hung up on is deciding which of the two best fits these goals.  I&#8217;ve used both approaches and like them both, but this is one of those debates that has no clear winner.  Let&#8217;s take a closer look at each approach.</p>
<p><strong>The Active Record Pattern</strong></p>
<p>In this model, an entity and its properties are directly mapped to a database table and its columns.  Additionally, every entity is implemented with its own insert, update, delete and select (CRUD) behaviors.  Method names like Save, Delete and Load are commonplace with many Active Record implementations.  Rounding out the package adds various static methods that expose query capabilities to allow filtering.  Having these behaviors included with the entities provides a convenient way of persisting state back to a data source.  I have used this pattern a lot and have had many successful projects that I credit the pattern for.  Needless to say, as with most solutions, it isn&#8217;t perfect.  There are a few cases where this pattern can create some interesting challenges.</p>
<p>Consider this case:  Cardinality, A.K.A. relationships with other entities.   Think of the classic customer and order example.  A customer can have many orders which is to say that the customer object has a one-to-many relationship with order objects.  Remember, the Active Record pattern exposes public <span style="font-family:courier new;">Save</span> methods on both the customer object and the order object.  What would you expect to happen when you call the <span style="font-family:courier new;">Save</span> method on the customer object?  Certainly the customer object will be saved to the database, but what about the orders?  If you&#8217;re using Ruby&#8217;s Active Record implementation, the orders that are associated with the customer object may or may not be saved depending on whether the customer&#8217;s <span style="font-family:courier new;">Save</span> method call is an initial or subsequent call.  Using Jammer.NET&#8217;s implementation, the associated orders are not saved at all.  The developer must take action by either modifying the <span style="font-family:courier new;">Save</span> method on the customer object to handle cascade saving or by calling the <span style="font-family:courier new;">Save</span> method on the orders collection manually.</p>
<p><strong>The Unit of Work Pattern</strong></p>
<p>According to Martin Fowler&#8217;s <a href="http://martinfowler.com/bliki/AnemicDomainModel.html" target="_blank">anemic domain model</a> anti-pattern, the domain model should only have objects that are named after the nouns in the domain space and connected to each other with rich relationship structures.  Furthermore, the behaviors of each object should model only those rules that are domain space specific.  This means that the Active Record pattern violates this rule because CRUD behaviors are forms of data store persistence logic not domain space logic.  Going by this definition, we must implement persistence using the <a href="http://martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank">Unit of Work</a> pattern.  Two great examples of this pattern is implemented by <a href="http://www.hibernate.org/" target="_blank">Hibernate</a> and <a href="http://www.hibernate.org/" target="_blank">Microsoft&#8217;s LINQ to SQL technology</a>.  Hibernate and LINQ to SQL take a sort of hybrid approach which combines both the Active Record pattern&#8217;s metadata mapping and the Unit of Work pattern.  This hybrid approach creates a very clean model for handling persistence regardless of cardinality between entity objects.  Using LINQ to SQL, the entities, for the most part, adhere to the notion of POCOs which are persistence ignorant.  Great right? Unfortunately, as with the Active Record approach, this model is also not without its challenges.</p>
<p>Consider this case: Objects that become disconnected from its Unit of Work container.  Let&#8217;s assume that you are writing a web application and you&#8217;re coding up a three step registration wizard.  Ideally, having the UoW container stay in scope through completion of the wizard is preferred.  Unfortunately, that may not be the best idea if your application needs have as light a footprint on memory usage as possible.  Considering this, you decide to let the UoW container go out of scope once your business objects are loaded causing the business objects to become disconnected.  Finally, the registration wizard reaches its last step which is to persist the state of the registration business object to the data store.  Because the UoW container got garbage collected a new container instance must be created and the business object must be re-attached.  I know what you&#8217;re probably thinking, &#8220;This logic is not so hard to write.  Why all the heartburn?&#8221;  The problem I have is with the additional lines of code that must be written to re-attach the entities.  These lines of code are entirely house keeping items that, in my opinion, muddy up the code.  In my opinion, this pattern also does not code as naturally as the Active Record pattern.  However, I do think it&#8217;s the better pattern in the sense that related entities are automatically handled by the UoW container.</p>
<p><strong>Sound Off!</strong></p>
<p>So what do you think?  Which pattern gets your vote?  Have I missed anything?  Help me to choose which way to go.  I&#8217;m sure this debate will likely live on for many years and I look forward to hearing from all of you.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=17&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/04/03/active-record-vs-unit-of-work/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
		<item>
		<title>My First Blog Post</title>
		<link>http://randolphcabral.wordpress.com/2008/03/28/my-first-blog-post/</link>
		<comments>http://randolphcabral.wordpress.com/2008/03/28/my-first-blog-post/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 18:57:32 +0000</pubDate>
		<dc:creator>Randolph Cabral</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://randolphcabral.wordpress.com/2008/03/28/my-first-blog-post/</guid>
		<description><![CDATA[Firstly, welcome to my home on the web!&#160; My name is Randolph Cabral, and I&#8217;m a Software Developer working for AMB Property Corporation in San Francisco, California. Well, I guess the time has come.&#160; I&#8217;m starting my own personal blog.&#160; I never imagined I would start one because I didn&#8217;t want to corrupt the world [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=6&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Firstly, welcome to my home on the web!&nbsp; My name is Randolph Cabral, and I&#8217;m a Software Developer working for <a href="http://www.amb.com">AMB Property Corporation</a> in <a href="http://maps.google.com/maps?q=San+Francisco,+CA,+United+States+of+America&amp;sa=X&amp;oi=map&amp;ct=title">San Francisco, California</a>.</p>
<p>Well, I guess the time has come.&nbsp; I&#8217;m starting my own personal blog.&nbsp; I never imagined I would start one because I didn&#8217;t want to corrupt the world with my useless musings, and trust me, I have many.&nbsp; I realize now that there is a compelling reason to maintain and write to a blog after all, and that reason is to share.</p>
<p>I&#8217;m not sure how or why this &#8220;sharing&#8221; concept had escaped me for so long.&nbsp; I like to think that I&#8217;m a generous and charitable person.&nbsp; But I guess that hasn&#8217;t been the case with certain aspects of my professional life.&nbsp; So here I am at the dawn of my attempt to share as much as my peers are willing to bear.&nbsp; But I&#8217;m not talking about sharing pointless politically charged opinions or to journal how my cat just learned to flush the toilet (no offense to those who blog about politics or their latest pet exploits).&nbsp; I&#8217;m talking about sharing something that others will hopefully find useful.&nbsp; I&#8217;m talking about sharing my technical endeavors as a computer software developer.</p>
<p>For years, I&#8217;ve frequented many technical blogs which have helped me on countless projects from a best practices stand point and also from an architectural standpoint.&nbsp; I continue to learn a great deal from their code snips and reading about the nature of the requirements that lead to the solution.&nbsp; It&#8217;s time that I give back and make my experiences public.&nbsp; It is my hope that at the very least, one of my posts helps a fellow programmer.</p>
<p>Let me be clear that I am by no means an expert in the field of software development.&nbsp; To make such a claim would be pompous and arrogant of me.&nbsp; I can only claim that I have had positive experiences in writing and implementing software which continues to live on as successful productive enterprise applications.</p>
<p>I look forward to sharing my experiences with you all &#8211; good or bad.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/randolphcabral.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/randolphcabral.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/randolphcabral.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/randolphcabral.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/randolphcabral.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=randolphcabral.wordpress.com&amp;blog=1442299&amp;post=6&amp;subd=randolphcabral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://randolphcabral.wordpress.com/2008/03/28/my-first-blog-post/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5f463d30a9f8f73cf54b6dabecbf8b6d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">randolphcabral</media:title>
		</media:content>
	</item>
	</channel>
</rss>
