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

<channel>
	<title>Udi Dahan - The Software Simplist &#187; ADO.NET</title>
	<atom:link href="http://www.udidahan.com/category/adonet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Sun, 08 Jan 2012 12:45:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>From CRUD to Domain-Driven Fluency</title>
		<link>http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/</link>
		<comments>http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 15:58:19 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Simplicity]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/02/15/from-crud-to-domain-driven-fluency/</guid>
		<description><![CDATA[I got a question about how to stay away from CRUD based service interfaces when the logic itself is like that, and I’ve found that this shift in thinking really needs more examples, so I’ve decided to put this out there:

For instance, in an HR system, the process of interviewing candidates &#8211; wouldn’t you just [...]]]></description>
			<content:encoded><![CDATA[<p>I got a question about how to stay away from CRUD based service interfaces when the logic itself is like that, and I’ve found that this shift in thinking really needs more examples, so I’ve decided to put this out there:<br />
<blockquote>
<p>For instance, in an HR system, the process of interviewing candidates &#8211; wouldn’t you just insert, update, and delete these Appointment objects?</p>
</blockquote>
<p>If I were to put on my domain-driven hat, I would describe those requirements differently – interview appointments have a lifecycle: proposed, accepted, cancelled, etc. It seems that only a user of the role HR Interviewer should be able to make appointments for themselves, so the service layer code would probably look something like this:
<p><!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode"><span class="kwrd">using</span> (ISession session = SessionFactory.OpenSession())
<span class="kwrd">using</span> (ITransaction tx = session.BeginTransaction())
{
    ICandidateInterviewer interviewer = session.Get&lt;ICandidateInterviewer&gt;(message.InterviewerId);
    ICandidate candidate = session.Get&lt;ICandidate&gt;(message.CandidateId);

    interviewer.ScheduleInterviewWith(candidate).At(message.RequestedTime);
    tx.Commit();
}
</pre>
<p>The “ScheduleInterviewWith” method accepts an ICandidate and returns an IAppointment. IAppointment has a method “At” which accepts a DateTime parameter and returns void – just changes the data of the appointment. The state of the appointment at creation time would probably be proposed. The appointment object would probably be added to the list of appointments for that interviewer – that’s what will cause it to be persisted automatically. </p>
<p>Later, when the candidate accepts the meeting, we could have the following method on ICandidate – void Accept(IAppointment); that would obviously check that the candidate is the right person for that interview, the appointment’s current state (not cancelled), etc – finally updating its state. What part of this looks like create, update, delete? If that’s what your service layer to domain interaction looks like, do you now know what your messages will be looking like?CRUD seems to be what most of us are familiar with. Moving to domain-driven thinking takes time and practice, but is well worth it. Contrast this with a more traditional O/R mapping solution: </p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}</p>
<p>.csharpcode pre { margin: 0em; }</p>
<p>.csharpcode .rem { color: #008000; }</p>
<p>.csharpcode .kwrd { color: #0000ff; }</p>
<p>.csharpcode .str { color: #006080; }</p>
<p>.csharpcode .op { color: #0000c0; }</p>
<p>.csharpcode .preproc { color: #cc6633; }</p>
<p>.csharpcode .asp { background-color: #ffff00; }</p>
<p>.csharpcode .html { color: #800000; }</p>
<p>.csharpcode .attr { color: #ff0000; }</p>
<p>.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}</p>
<p>.csharpcode .lnum { color: #606060; }
</style>
<pre class="csharpcode"><span class="kwrd">using</span> (ISession session = SessionFactory.OpenSession())
<span class="kwrd">using</span> (ITransaction tx = session.BeginTransaction())
{
    ICandidateInterviewer interviewer = session.Get&lt;ICandidateInterviewer&gt;(message.InterviewerId);
    ICandidate candidate = session.Get&lt;ICandidate&gt;(message.CandidateId); 

    Appointment a = <span class="kwrd">new</span> Appointment(); 

    a.Interviewer = interviewer;
    interviewer.Appointments.Add(a); 

    a.Candidate = candidate;
    candidate.Appointments.Add(a); 

    a.Time = message.RequestedTime; 

    session.Save(a);  

    tx.Commit();
} 
</pre>
<p>As you can see, we’ve got simpler, more expressive, and more testable code when employing the domain model pattern, than using “just” O/R mapping. I’m not saying that the domain model pattern doesn’t need O/R mapping in the background for it to work. But that’s just it &#8211; the persistence gunk needs to be in the background and the business logic needs to be encapsulated. </p>
<p>So, while I’ll agree with Dave that the Domain Model is <a href="http://laribee.com/blog/2007/05/08/domain-model-less-pattern-more-lifestyle/">more lifestyle than pattern</a>, I would argue against these conclusions: </p>
<blockquote>
<p>If this post had a point, it’s only to share the idea that Domain Model is a big, big thing. It’s probably overkill in a lot of cases where you have simple applications that have very simple purposes.</p>
</blockquote>
<p>As you just saw in the example above, there is no “overkill” to be seen. The domain model in the example wasn’t “a big, big thing”. </p>
<p>The domain model. Use it. </p>
<p>Why not have a better lifestyle?&nbsp;&nbsp; <img alt=";-)" src="http://udidahan.weblogs.us/wp-includes/images/smilies/icon_wink.gif"></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/02/15/from-crud-to-domain-driven-fluency/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Fetching Strategy NHibernate Implementation Available</title>
		<link>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/</link>
		<comments>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 00:54:02 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/09/16/fetching-strategy-nhibernate-implementation-available/</guid>
		<description><![CDATA[A couple of months ago I put out a post discussing one way to implement custom fetching strategies. Anyway, I finally got around to putting my money where my mouth was&#8230;
So, I&#8217;ve implemented the pattern in NHibernate, adding the following method to ISession:
T Create&#60;T&#62;();
As well as adding the following interface to the NHibernate package:

  [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of months ago I put out a <a href="http://udidahan.weblogs.us/2007/04/23/fetching-strategy-design/">post discussing one way to implement custom fetching strategies</a>. Anyway, I finally got around to putting my money where my mouth was&#8230;</p>
<p>So, I&#8217;ve implemented the pattern in NHibernate, adding the following method to ISession:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">T Create&lt;T&gt;();</div>
<p>As well as adding the following interface to the NHibernate package:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
    public interface IFetchingStrategy&lt;T&gt;<br />
    {<br />
        ICriteria AddFetchJoinTo(ICriteria criteria);<br />
    }
</div>
<p>All this enables you to have a stronger separation between your service layer classes and your domain model class, as well as for you to express each service-level use case as a domain concept &#8211; an interface.</p>
<p>Once you have such an interface, you can create a fetching strategy for that use case and define exactly how deep of an object graph you want to load so that you only hit the DB once for that use case.</p>
<p>The nice thing is that its all configured with Spring. In other words, if you the entry for your fetching strategy class exists, you get the improved performance, if it doesn&#8217;t, you don&#8217;t. All without touching your service layer classes.</p>
<p>Just as an example, when I&#8217;m in the use case modeled by &#8220;ICustomer&#8221;, I want to get all the customer&#8217;s orders, and their orderlines. This would be done by having a class like this:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
    public class CustomerFetchingStrategy : IFetchingStrategy&lt;ICustomer&gt;<br />
    {<br />
        public ICriteria AddFetchJoinTo(ICriteria criteria)<br />
        {<br />
            criteria.SetFetchMode(&#8221;orders&#8221;, FetchMode.Eager).<br />
                SetFetchMode(&#8221;orders.orderLines&#8221;, FetchMode.Eager);</p>
<p>            return criteria;<br />
        }<br />
    }
</p></div>
<p>And the configuration would look like this (as a part of the regular spring template):</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
      &lt;object id=&#8221;CustomerFetchingStrategy&#8221; type=&#8221;Domain.Persistence.CustomerFetchingStrategy, Domain.Persistence&#8221; /&gt;
</div>
<p>If you want to take a look at the full solution, you can find it here. For some reason, the combined file was too big for the upload on my blog so it&#8217;s split into two. Unzip both packages into the same directory. You&#8217;ll find a file called &#8220;db_scripts.sql&#8221; which contains the schema for the DB. Don&#8217;t forget to update your connection string in the &#8220;hibernate.cfg.xml&#8221;. If you&#8217;re looking for the changes I made to the NHibernate source, you can find it in the &#8220;Updated NHibernate Files&#8221; directory. The only real change is to the &#8220;SessionImpl.cs&#8221; file.</p>
<p><a href='http://udidahan.weblogs.us/wp-content/uploads/libraries.zip' title='libraries.zip'>Relevant NHibernate and Spring binaries</a>.</p>
<p><a href='http://udidahan.weblogs.us/wp-content/uploads/objectrelationalmappingdemo4.zip' title='objectrelationalmappingdemo.zip'>Source code of example</a>.</p>
<p>BTW, there is some intelligent thread-safe caching going on in SessionImpl now so that you get a much smaller performance hit (in terms of code that uses reflection) on subsequent usages of the same interfaces.</p>
<p>Let me know what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/09/16/fetching-strategy-nhibernate-implementation-available/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>DevHawk not thrilled about Astoria either</title>
		<link>http://www.udidahan.com/2007/05/25/devhawk-not-trilled-about-astoria-either/</link>
		<comments>http://www.udidahan.com/2007/05/25/devhawk-not-trilled-about-astoria-either/#comments</comments>
		<pubDate>Fri, 25 May 2007 07:56:28 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/05/25/devhawk-not-trilled-about-astoria-either/</guid>
		<description><![CDATA[It appears that more people are coming to the same conclusions that I have about Astoria (Astoria, SDO, and Irrelevance), Microsoft&#8217;s new &#8220;Data Services for the Web&#8221; initiative.
DevHawk (aka Harry Pierson) writes:

As you might guess then, I’m not a fan of Astoria. I believe the sweet spot for so called “data services” will be read [...]]]></description>
			<content:encoded><![CDATA[<p>It appears that more people are coming to the same conclusions that I have about Astoria (<a href="http://udidahan.weblogs.us/2007/05/01/astoria-sdo-and-irrelevance/">Astoria, SDO, and Irrelevance</a>), Microsoft&#8217;s new &#8220;Data Services for the Web&#8221; initiative.</p>
<p>DevHawk (aka Harry Pierson) <a href="http://devhawk.net/2007/05/24/REST+Is+Neither+CRUD+Nor+CRAP.aspx">writes</a>:</p>
<blockquote><p>
As you might guess then, I’m not a fan of Astoria. I believe the sweet spot for so called “data services” will be read only (because they don&#8217;t need transactions, natch). I&#8217;m sure there are some read/write scenarios Astoria will be useful for, but I think they will be limited &#8211; at least within the enterprise.
</p></blockquote>
<p>After catching up to <a href="http://blogs.msdn.com/pablo/">Pablo Castro</a> (the man behind Astoria) at <a href="http://www.DevTeach.com">DevTeach</a>, and chatting with him and <a href="http://blogs.msdn.com/timmall/">Tim Mall</a> about Astoria, I heard something interesting. In order to provide business context for updates, you will be able to use something like a WS-Action header.</p>
<p>So, it&#8217;s based on REST, but for updates, it&#8217;s like WS-*. Hmm&#8230; Best of both worlds, or worst? What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/05/25/devhawk-not-trilled-about-astoria-either/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>NHibernate will rule, because Ayende already does</title>
		<link>http://www.udidahan.com/2007/05/20/nhibernate-will-rule-because-ayende-already-does/</link>
		<comments>http://www.udidahan.com/2007/05/20/nhibernate-will-rule-because-ayende-already-does/#comments</comments>
		<pubDate>Sun, 20 May 2007 21:56:30 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/05/20/nhibernate-will-rule-because-ayende-already-does/</guid>
		<description><![CDATA[First I find out that NHibernate does support &#8220;Persistence by Reachability&#8221;, even though the docs say it doesn&#8217;t. Next, Ayende makes it support multiple queries in a single DB roundtrip, something I&#8217;ve been asking all the other O/R mappers out there to do. To top it off, he&#8217;s got his sights set on solving the [...]]]></description>
			<content:encoded><![CDATA[<p>First I find out that <a href="http://udidahan.weblogs.us/category/nhibernate/">NHibernate</a> does support &#8220;Persistence by Reachability&#8221;, even though the docs say it doesn&#8217;t. Next, Ayende makes it support <a href="http://ayende.com/Blog/archive/2007/05/20/NHibernate-Multi-Criteria.aspx">multiple queries in a single DB roundtrip</a>, something I&#8217;ve been asking all the other O/R mappers out there to do. To top it off, he&#8217;s got his sights set on solving the issues I raised in my talk on Complex Business Logic with DDD and O/R Mapping at DevTeach. That&#8217;s right, he&#8217;s going to give me my decorators and state machines.</p>
<p>I love you, Oren.</p>
<p>I know that the ADO.NET Entity Framework guys are open to this as well, but I&#8217;m pretty sure that the &#8220;Entity Model&#8221; thinking will hold them back. You just can&#8217;t divorce data and behavior &#8211; not when employing state machines or decorators.</p>
<p>I&#8217;m sold.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/05/20/nhibernate-will-rule-because-ayende-already-does/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Podcast] Occasionally Connected Smart Clients and ADO.NET Sync Services</title>
		<link>http://www.udidahan.com/2007/04/17/podcast-occasionally-connected-smart-clients-and-adonet-sync-services/</link>
		<comments>http://www.udidahan.com/2007/04/17/podcast-occasionally-connected-smart-clients-and-adonet-sync-services/#comments</comments>
		<pubDate>Tue, 17 Apr 2007 21:12:15 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[DataSets]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Smart Client]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/04/17/podcast-occasionally-connected-smart-clients-and-adonet-sync-services/</guid>
		<description><![CDATA[This week&#8217;s question comes from Oran who asks:

Hi Udi, 
I&#8217;m enjoying the recent discussion on Entity Framework, disconnected clients, Unit of Work, and messaging.  A few weeks ago I wrote a note to self to &#8220;Ask Udi&#8221; about the new ADO.NET Sync Services coming out of Microsoft, and this seems to be the perfect [...]]]></description>
			<content:encoded><![CDATA[<p>This week&#8217;s question comes from Oran who asks:</p>
<blockquote><p>
Hi Udi, </p>
<p>I&#8217;m enjoying the recent discussion on <a href="http://udidahan.weblogs.us/2007/03/30/entity-framework-disconnected-problems-solutions/">Entity Framework</a>, <a href="http://udidahan.weblogs.us/2007/04/04/occasionally-connected-systems-architecture/">disconnected clients</a>, Unit of Work, and <a href="http://udidahan.weblogs.us/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/">messaging</a>.  A few weeks ago I wrote a note to self to <a href="/ask-udi">&#8220;Ask Udi&#8221;</a> about the new ADO.NET Sync Services coming out of Microsoft, and this seems to be the perfect timing.  </p>
<p>It really seems that Sync Services is meant to address the disconnected problem raised by Andres, but it appears to be primarily targeted at enabling <a href="http://udidahan.weblogs.us/category/datasets/">DataSet</a>-centric, grid-oriented UIs, not task-oriented UIs.  They are spinning Sync Services as being an <a href="http://udidahan.weblogs.us/category/soa/">&#8220;SOA&#8221;</a> way of doing data synchronization because &#8220;it uses <a href="http://udidahan.weblogs.us/category/wcf/">WCF</a>&#8221; and &#8221; supports n-tier&#8221;.  But under the hood it&#8217;s all about DataSet-style deltas.  See Steve Lasker&#8217;s <a href="http://blogs.msdn.com/stevelasker/archive/2007/03/18/QAforOCS_2D00_SyncServicesForAdoNet.aspx">first Q&#038;A for the SOA spin</a>, and the rest of his blog for more info.</p>
<p>I&#8217;m curious what your thoughts are on the subject.  Do you see Sync Services as a valid service-oriented solution for occasionally-connected clients, or is it just another attempt by the ADO.NET team to keep us all hooked on DataSet-driven development?</p>
<p>Oran
</p></blockquote>
<p>Get it via the Dr. Dobb&#8217;s site <a href="http://ddj.com/dept/webservices/199100027">here</a>.</p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/070416ud01.mp3?podcast=070416ud01.mp3">here</a>.</p>
<p><u>Additional References</u></p>
<ul>
<li><a href="http://udidahan.weblogs.us/2007/04/04/occasionally-connected-systems-architecture/">Occasionally Connected Systems Architecture</a></li>
<li><a href="http://udidahan.weblogs.us/2007/03/30/entity-framework-disconnected-problems-solutions/">Entity Framework: Disconnected Problems &#038; Solutions</a></li>
<li><a href="http://udidahan.weblogs.us/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/">Tasks, Messages, &#038; Transactions&#8211;the holy trinity</a></li>
</ul>
<p>Want more? Go to the <a href="/ask-udi">&#8220;Ask Udi&#8221; archives</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/04/17/podcast-occasionally-connected-smart-clients-and-adonet-sync-services/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://www.dobbsprojects.com/media/newengine/dynamp.php/070416ud01.mp3?podcast=070416ud01.mp3" length="14630866" type="audio/mp3" />
		</item>
		<item>
		<title>Tasks, Messages, &amp; Transactions – the holy trinity</title>
		<link>http://www.udidahan.com/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/</link>
		<comments>http://www.udidahan.com/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/#comments</comments>
		<pubDate>Sat, 31 Mar 2007 11:03:19 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/</guid>
		<description><![CDATA[The discussion is picking up around disconnected Web Service interaction scenarios. Here&#8217;s a summary of what&#8217;s going on for those just joining us, but I would suggest reading the full posts as well:
Andres: &#8220;Basically, there is no disconnected mode&#8230; if you plan to build a multi-tier application with ADO.NET Orcas in the middle tier, you [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">The discussion is picking up around disconnected Web Service interaction scenarios. Here&rsquo;s a summary of what&rsquo;s going on for those just joining us, but I would suggest reading the full posts as well:<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><a href="http://weblogs.asp.net/aaguiar/archive/2007/03/30/ado-net-orcas-entity-framework-and-disconnected-operation.aspx"><font face="Calibri" color="#800080" size="3">Andres</font></a><font size="3"><font face="Calibri">: &ldquo;Basically, there is no disconnected mode&hellip; if you plan to build a multi-tier application with ADO.NET Orcas in the middle tier, you will need to hack your own change tracking mechanism in the client, send the whole changeset, and apply it in the middle tier.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><a href="http://udidahan.weblogs.us/2007/03/30/entity-framework-disconnected-problems-solutions/"><font face="Calibri" size="3">Udi</font></a><font size="3"><font face="Calibri">: &ldquo;[In] the UI, &hellip; tasks often corresponded very well to the coarse-grained messages we employed in terms of SOA.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><a href="http://weblogs.asp.net/jezell/archive/2007/03/30/soa-and-updates.aspx"><font face="Calibri" size="3">Jesse</font></a><font size="3"><font face="Calibri">: &ldquo;I have to disagree with Andres and agree with Udi.&rdquo; <o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">(Sorry, I just couldn&rsquo;t resist. Here&rsquo;s the important part) <o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">&ldquo;Andres rightly points out that you don&#8217;t want 5 different methods for updating an order. Although you technically could do it that way, you probably don&#8217;t want to be ignoring the transactional context of the conversation or locking tables for significant time periods.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">And, &ldquo;The backend will still have all the update methods you are used to using, so you&#8217;re not writing a bunch of extra code in the DB. However, this approach is far more powerful. One reason why is that now you have an operation defined and you can control everything about that operation. You know when the call comes in through that method that you have a customer service rep trying to update an order and can build in logic based off of that.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><a href="http://weblogs.asp.net/aaguiar/archive/2007/03/30/re-disconnected-problems-and-solutions.aspx"><font face="Calibri" color="#800080" size="3">Andres</font></a><font size="3"><font face="Calibri">: &ldquo;Now, we need to send those changes to the server, together, because I want them executed in a single transaction. I cannot have a service called &#8216;ModifyOrderCustomerInformation&#8217;, another &#8216;AddALineToOrder&#8217; and &#8216;DeleteLineFromOrder&#8217;. I need an &#8216;UpdateOrder&#8217; service. You can use a diffgram to do it, or you could build your own change-serialization mechanism.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">And, &ldquo;The only way I see is to map the UI to the service interface, so the user can &#8216;Change Address&#8217; or &#8216;Update Marital Status&#8217; as different operations in the UI layer, but I can&#8217;t let the user &#8216;Modify the Customer&#8217;. It&#8217;s a lot of work, and I seriously doubt that the users will like it.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><font size="3"><font face="Calibri"><strong><span lang="EN-US" style="mso-ansi-language: EN-US">OK, now we&rsquo;re all set.</span></strong><span lang="EN-US" style="mso-ansi-language: EN-US"><o:p></o:p></span></font></font></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">Just to get something small out of the way, every Human-Computer Interaction (HCI) professional I have worked with has been in favor of task-based UIs. Every user that I have met that has used both styles of UI, task based and &ldquo;grid&rdquo; based, has reported that they were more productive when using the task based UI for &ldquo;interactive work&rdquo;. Data entry is not interactive work, so grids might be more suitable there, although improvements in bulk-loading technology and OCR have decreased the amount of &ldquo;plain&rdquo; data entry that I&rsquo;m encountering. It also may be that I&rsquo;m working less on systems where data entry is of significant importance.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">First of all let&rsquo;s agree that writing business logic for something like &ldquo;DeleteLineFromOrder&rdquo; or &ldquo;UpdateMaritalStatus&rdquo; is easier than for &ldquo;UpdateOrder&rdquo;, given that it fit with the overall system design.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">Second, let&rsquo;s agree that the business logic for something generic like &ldquo;UpdateOrder&rdquo; is composed of the various specific cases like &ldquo;DeleteLineFromOrder&rdquo; and &ldquo;AddLineToOrder&rdquo;.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">Third, let&rsquo;s agree that if the UI was task based, it would be easy for the client side to activate the correct web service/method &ndash; seeing as there is a high correlation between the tasks and the service methods.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri" size="3">Therefore, the question becomes how do we do all the above specific work in a single transaction? One answer may be to make the service statefull and using something like WS-Atomic Transaction to tie the various calls together. The problems in this approach are already well known. Another solution uses a messaging paradigm, something </font><a href="http://udidahan.weblogs.us/2006/06/02/can-indigo-be-my-bus/"><font face="Calibri" size="3">I wrote about before</font></a><font size="3"><font face="Calibri">.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">If we represent each of the tasks not as &ldquo;web methods&rdquo;, but rather as messages we could send all these messages together in one envelope to the server, and have it process all of them in a single transaction, activating the specific business logic pieces one after the other.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">I&rsquo;ll be using a code-first approach to describe the solution instead of an XML-first one since it abstracts away the technology, but it is still a contract-first approach.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">Each message type is just a class that implements the &ldquo;IMessage&rdquo; interface. So we&rsquo;d have a class called &ldquo;DeleteLineFromOrderMessage&rdquo; which is a Data-Transfer Object (DTO) whose members/properties are the data needed for processing &ndash; in this case, the order Id and the order line number. The same would be true for the class &ldquo;AddOrderLineMessage&rdquo;, it would contain the order Id and some other member for the order line data quite probably a DTO itself (so that we can use it in other places as well).<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">The client would generate an instance of the appropriate message class as the user finishes each sub-task, saving them up. When the user would click &ldquo;confirm&rdquo;, the client would send all these message objects to the server in one go with this API, <o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="FONT-FAMILY: Consolas; mso-ansi-language: EN-US"><font size="3">void IBus.Send(params IMessage[] messages);<o:p></o:p></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">Like so:<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="FONT-FAMILY: Consolas; mso-ansi-language: EN-US"><font size="3">myBus.Send(addOrderLineMsg, delOrderLineMsg);<o:p></o:p></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">The bus would take all these objects and wrap them in a single SOAP envelope, and send them to the server, probably on a transactional channel, but that&rsquo;s a configuration issue. At the server side, the bus would activate the transaction (because of the transactional channel) and start dispatching each of the specific messages to its message handler, one at a time, in the same thread.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">So as you can see, there is no &ldquo;transactional conversation&rdquo;, and therefore we&rsquo;re not locking tables in between calls, because we&rsquo;ve gotten rid of &ldquo;in between&rdquo;. It&rsquo;s just like the generic update in terms of transaction time and network hops, just with specific, simple business logic.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri" size="3">Andres might retort to that, &ldquo;Even if Udi is right, and that&#8217;s the way applications should be built, I doubt most mere mortals in Earth will want to do it.&rdquo; In fact, </font><a href="http://weblogs.asp.net/aaguiar/archive/2007/03/30/re-disconnected-problems-and-solutions.aspx"><font face="Calibri" color="#800080" size="3">he did</font></a><font face="Calibri" size="3"> </font></span><font size="3"><span lang="EN-US" style="FONT-FAMILY: Wingdings; mso-ansi-language: EN-US; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><span style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">J</span></span><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri"> If the frameworks supporting this style of development were supplied by Microsoft, I&rsquo;m sure that most developers wouldn&rsquo;t have a problem with it. When provided with such a framework, every developer I&rsquo;ve worked with said that they wouldn&rsquo;t want to go back to the &ldquo;old way&rdquo; (would that make Orcas outdated?). I&rsquo;ll be putting up my frameworks soon, as well as examples on how to use them, it&rsquo;s just taking longer than I expected.<o:p></o:p></font></span></font></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri" size="3">Before closing, I just wanted to address </font><a href="http://weblogs.asp.net/aaguiar/archive/2007/03/30/re-disconnected-problems-and-solutions.aspx"><font face="Calibri" color="#800080" size="3">the points Andres raised about concurrency</font></a><font size="3"><font face="Calibri">:<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font size="3"><font face="Calibri">&ldquo;You could also need to know the previous values for optimistic concurrency checkings.&rdquo;<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri" size="3">I&rsquo;ve written about how to do this before in regards to </font><a href="http://udidahan.weblogs.us/2007/01/22/realistic-concurrency/"><font face="Calibri" color="#800080" size="3">Realistic Concurrency</font></a><font face="Calibri" size="3">, and the best example I have in terms of code is </font><a href="http://udidahan.weblogs.us/2007/03/06/better-domain-driven-design-implementation/"><font face="Calibri" color="#800080" size="3">Better Domain-Driven Design Implementation</font></a><font size="3"><font face="Calibri">.<o:p></o:p></font></font></span></p>
<p class="MsoNormal" style="MARGIN: 0cm 0cm 10pt"><span lang="EN-US" style="mso-ansi-language: EN-US"><font face="Calibri" size="3">This has gone a little longer than I planned, but I still don&rsquo;t think I&rsquo;ve covered everything in enough depth. I&rsquo;d most appreciate investigative questions to help me shed light on the murkier parts of this, either as comments, posts on your own blog, or even via </font><a href="mailto:%20AskUdi@UdiDahan.com"><font face="Calibri" size="3">email</font></a><font size="3"><font face="Calibri">. Let&rsquo;s continue the conversation.<o:p></o:p></font></font></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/03/31/tasks-messages-transactions-%e2%80%93-the-holy-trinity/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Entity Framework: Disconnected Problems &amp; Solutions</title>
		<link>http://www.udidahan.com/2007/03/30/entity-framework-disconnected-problems-solutions/</link>
		<comments>http://www.udidahan.com/2007/03/30/entity-framework-disconnected-problems-solutions/#comments</comments>
		<pubDate>Fri, 30 Mar 2007 20:30:40 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Smart Client]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/archives/438</guid>
		<description><![CDATA[Andres Aguiar points out an enormous change to the behavior of data access in tiered architectures that is coming with the ADO.NET Orcas Entity Framework. He sums it up nicely, “Basically, there is no disconnected mode.” He then goes on to talk about the ramifications of this:
“This basically means that if you plan to build [...]]]></description>
			<content:encoded><![CDATA[<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>Andres Aguiar points out </FONT><A href="http://weblogs.asp.net/aaguiar/archive/2007/03/30/ado-net-orcas-entity-framework-and-disconnected-operation.aspx"><FONT face=Calibri>an enormous change</FONT></A><FONT face=Calibri> to the behavior of data access in tiered architectures that is coming with the ADO.NET Orcas Entity Framework. He sums it up nicely, “Basically, there is no disconnected mode.” He then goes on to talk about the ramifications of this:</FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><I><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>“This basically means that if you plan to build a multi-tier application with ADO.NET Orcas in the middle tier, you will need to hack your own change tracking mechanism in the client, send the whole changeset, and apply it in the middle tier. From this point of view, it&#8217;s a huge step backwards, as that&#8217;s something we already have with DataSets today.”<o:p></o:p></FONT></SPAN></I></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I do quite a bit of work on large-scale distributed systems, some that could even be called “multi-tier”, but I really don’t like that term. I’ve got to tell you, I’m not that worried. I could say that it’s because I’m using an object/relational mapping tool, but then again, the Entity Framework is supposed to be that too. It also might be because </FONT><A href="http://udidahan.weblogs.us/2006/11/21/re-datasets/"><FONT face=Calibri>I don’t use DataSets that much today anyway</FONT></A><FONT face=Calibri>, but that begs Andres’ question – did I develop my own change-tracking mechanism on the client?<o:p></o:p></FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>The answer lies in the second part of Andres’ question, I don’t “send the whole changeset, and apply it in the middle tier”. I have an </FONT><A href="http://udidahan.weblogs.us/2007/03/28/podcast-datasets-web-services/"><FONT face=Calibri>entire podcast</FONT></A><FONT face=Calibri> up on why I don’t think that that’s a good idea, specifically around Web Services and SOA, but it’s broadly applicable. However, the question remains, what do we do about the client side?<o:p></o:p></FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>Just over a year ago, me and </FONT><A href="http://blog.springframework.com/arjen/"><FONT face=Calibri>Arjen Poutsma</FONT></A><FONT face=Calibri> (of Spring fame) had a </FONT><A href="http://udidahan.weblogs.us/2007/01/16/thoughts-about-usability/"><FONT face=Calibri>discussion</FONT></A><FONT face=Calibri> about this exact topic at the Software Architecture Workshop in beautiful Cortina, Italy. Here’s the important part:<o:p></o:p></FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I think it started by me saying that services should not expose CRUD style operations. Arjen countered by mentioning that most user interfaces in line-of-business applications exposed the same model to the user by having them fill out data in grids. My retort to that was that while humans can get used to almost anything as long as it’s consistent, that doesn’t mean that it is a good solution. In the systems that I work on there is usually an HCI (human-computer interaction) person on the project who designs the UI, mostly around the tasks they perform. These tasks often corresponded very well to the coarse-grained messages we employed in terms of SOA. We finally agreed that the successor of SOA would be TOA (Task-Oriented Architecture) in its aggregation of client-side aspects to the already server-centric principles of SOA.<o:p></o:p></FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>As a concrete example, instead of updating customer data in a grid showing everything laid out flat, users would activate tasks like “Change address”, or “Update marital status”. The form shown would contain only the relevant data to be updated – no need to perform “change tracking”, it is perfectly clear what data needs to be sent. Furthermore, the intent behind the changed data would be sent as well – the server wouldn’t apply the data generically “in the middle tier”. Rather, the current customer data would be retrieved as a part of the customer object, and the appropriate method called upon it (ChangeAddress, or UpdateMaritalStatus) with the relevant data.<o:p></o:p></FONT></SPAN></P></p>
<p><P class=MsoNormal style="MARGIN: 0cm 0cm 10pt"><SPAN lang=EN-US style="mso-ansi-language: EN-US"><FONT face=Calibri>I actually view this change in the Entity Framework as a step forward, it’s like taking off the training wheels. I’m positive that most developers will be able to make the change and move to these more advanced architectures.<o:p></o:p></FONT></SPAN></P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/03/30/entity-framework-disconnected-problems-solutions/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Dataset – O/R mapping rumble at TechEd MVP Dinner</title>
		<link>http://www.udidahan.com/2006/11/09/dataset-%e2%80%93-or-mapping-rumble-at-teched-mvp-dinner/</link>
		<comments>http://www.udidahan.com/2006/11/09/dataset-%e2%80%93-or-mapping-rumble-at-teched-mvp-dinner/#comments</comments>
		<pubDate>Thu, 09 Nov 2006 13:11:05 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[DataSets]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Scalability]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/348</guid>
		<description><![CDATA[So, last night I was at the MVP dinner in TechEd and everything was nice. We had a nice meal, conversation was nice, weather was… nice. And then the volume started to rise, slowly at first, so as you don’t quite notice it. After a bit, you kind of stop talking and look around. And then I hear it…
<br/><br/>
&#60;WWF announcer voice&#62;<br/>
Are you ready… to RUMBLE !?!?<br/>
&#60;/WWF announcer voice&#62;<br/>
<br/>
It was datasets vs. O/R mapping, a slight twist on the infamous datasets vs. custom objects debate, all over again. They pulled me in, kicking and screaming, I swear, I really do. The lines were drawn, maintainability, performance, all the things that architects like to philosophize about in terms of other people’s work.
<br/><br/>
Anyway, I won’t give you the play-by-play ‘cause we were there almost all night. I’ll just cut to the chase.
<br/><br/>
First things first – any comparison of solutions without the context of a problem leads nowhere, fast, and stays there. So the first question I asked (when I got the chance to speak) was “are we talking about querying/reporting here?” and the answer was something like “well, yeah, but a lot of other things too”. So my suggestion was that we discuss the solutions in terms of two contexts -  querying/reporting and OLTP.
<br/><br/>
What I mean by OLTP is the data-updating kind of work that you do on certain items. Examples of this include “insert order”, “change customer address”, and “discount product”. Querying/reporting doesn’t change data, and often involves dealing with large sets of data pulled from different kinds of entities (in ERD terms).
<br/><br/>
Luckily, my suggestion to deal with them separately was accepted. Secondly, I proposed that an object model (specifically implementing the Domain Model pattern) designed for OLTP would perform poorly when used for querying/reporting – simply because it wasn’t designed for it. The structure of a domain model is such that it makes it possible to define / implement business rules in one place. That’s possible, not easy. 
<br/><br/>
Well, the dataset people weren’t going to just hand me the OLTP side of the equation without a fight, so they mentioned how easy it was to just “AcceptChanges”, and that my way was much more complex. My rebuttal came in the form of a question (are you seeing a pattern here?): Do you just swallow DbConcurrencyExceptions are do you throw all the user’s changes away when it happens? I didn’t quite make out the answer since there was a lot of mumbling going on, but I’m pretty sure they had one. I mean, you can’t develop multi-user systems using datasets without running into this situation.
<br/><br/>
The example that clinched OLTP was this. Two users perform a change to the same entity at the same time – one updates the customer’s marital status, the other changes their address. At the business level, there is no concurrency problem here. Both changes should go through. When using datasets, and those changes are bundled up with a bunch of other changes, and the whole snapshot is sent together from each user, you get a DbConcurrencyException. Like I said, I’m sure there’s a solution to it, I just haven’t heard it yet.
<br/><br/>
Now, here’s where things get interesting. I didn’t say that using a domain model automatically solves this problem. Rather, I described how each client could send a specific message, one a ChangeMaritalStatusMessage, the other a ChangeAddressMessage, to the server – in essence, giving the server the context in which each bit of data is relevant. The server could just open a transaction, get the customer object based on its Id, call a method on the customer (ChangeMaritalStatus or ChangeAddress), and commit the transaction. If two of these messages got to the server at the same time, the transactions would just cause them to be performed serially, and both transactions would succeed. The important part here is not losing the context of the changes.
<br/><br/>
When we talked about querying/reporting, things seemed quite a bit clearer. Datasets, or rather datatables seemed like a fine solution – most 3rd party controls support them out of the box. One guy mentioned that datasets performed poorly for large sets of data and that by designing custom entities for the result set, he could improve performance and memory utilization by, like, 70%. To tell you the truth, I think that if you need the performance, do it, if not, just use datasets. There isn’t much of an issue of correctness.
<br/><br/>
Just as an ending comment, in response to something someone said about scalability, I asked if they were reporting against the live OLTP data. The response was “yes”. Well, there’s a database scalability problem if I ever saw one. OLTP works most correctly when employing transactions that have an isolation level of serializable. The problem with them is that they lock up the whole table, or get blocked when a table scan is going on. Querying often results in a table scan. You can see the problem. Anyway, a common solution to this problem is to just reduce the isolation level, a quick fix that improves performance almost immediately. You take one hit in that your reports may be showing incorrect data, especially if they do aggregate type work. You might take another hit if your OLTP transactions need to do aggregate type work themselves. That second hit is pretty much unacceptable. A different solution is to accept the fact that the heaviest querying can usually show data that isn’t up to date up to the second.
<br/><br/>
In such a solution, you would have another database for reporting. It wouldn’t be just a replica of the OLTP database, but rather a lot more denormalized – which is a really not nice way of saying designed for reporting. You could then move the data from your OLTP database to the reporting database in some way (more to come on this topic) and you increase the scalability of your database. Just to define that a bit better – your OLTP database will be able to handle more transactions per unit of time, and reports will run faster, meaning that you will both improve their latency and the number of queries that can be handled per unit of time.
<br/><br/>
Anyway, I was pretty tired after all that, but if I had to sum it up I’d say something like this: before debating solutions, define the problem, you get a lot more insight into the solutions and you get it faster. That’s just win-win all around.]]></description>
			<content:encoded><![CDATA[<p>So, last night I was at the MVP dinner in TechEd and everything was nice. We had a nice meal, conversation was nice, weather was… nice. And then the volume started to rise, slowly at first, so as you don’t quite notice it. After a bit, you kind of stop talking and look around. And then I hear it…</p>
<p>&lt;WWF announcer voice&gt;<br />
Are you ready… to RUMBLE !?!?<br />
&lt;/WWF announcer voice&gt;</p>
<p>It was <a href="http://udidahan.weblogs.us/category/datasets/">Datasets</a> vs. <a href="http://udidahan.weblogs.us/category/nhibernate/">O/R mapping</a>, a slight twist on the infamous datasets vs. custom objects debate, all over again. They pulled me in, kicking and screaming, I swear, I really do. The lines were drawn, maintainability, performance, all the things that architects like to philosophize about in terms of other people’s work.</p>
<p>Anyway, I won’t give you the play-by-play ‘cause we were there almost all night. I’ll just cut to the chase.</p>
<p>First things first – any comparison of solutions without the context of a problem leads nowhere, fast, and stays there. So the first question I asked (when I got the chance to speak) was “are we talking about querying/reporting here?” and the answer was something like “well, yeah, but a lot of other things too”. So my suggestion was that we discuss the solutions in terms of two contexts &#8211;  querying/reporting and OLTP.</p>
<p>What I mean by OLTP is the data-updating kind of work that you do on certain items. Examples of this include “insert order”, “change customer address”, and “discount product”. Querying/reporting doesn’t change data, and often involves dealing with large sets of data pulled from different kinds of entities (in ERD terms).</p>
<p>Luckily, my suggestion to deal with them separately was accepted. Secondly, I proposed that an object model (specifically implementing the <a href="http://udidahan.weblogs.us/2007/04/21/domain-model-pattern/">Domain Model pattern</a>) designed for OLTP would perform poorly when used for querying/reporting – simply because it wasn’t designed for it. The structure of a domain model is such that it makes it possible to define / implement <a href="http://udidahan.weblogs.us/category/business-rules/">business rules</a> in one place. That’s possible, not easy. </p>
<p>Well, the dataset people weren’t going to just hand me the OLTP side of the equation without a fight, so they mentioned how easy it was to just “AcceptChanges”, and that my way was much more complex. My rebuttal came in the form of a question (are you seeing a pattern here?): Do you just swallow DbConcurrencyExceptions are do you throw all the user’s changes away when it happens? I didn’t quite make out the answer since there was a lot of mumbling going on, but I’m pretty sure they had one. I mean, you can’t develop multi-user systems using datasets without running into this situation.</p>
<p>The example that clinched OLTP was this. Two users perform a change to the same entity at the same time – one updates the customer’s marital status, the other changes their address. At the business level, there is no <a href="http://udidahan.weblogs.us/2007/01/22/realistic-concurrency/">concurrency</a> problem here. Both changes should go through. When using datasets, and those changes are bundled up with a bunch of other changes, and the whole snapshot is sent together from each user, you get a DbConcurrencyException. Like I said, I’m sure there’s a solution to it, I just haven’t heard it yet.</p>
<p>Now, here’s where things get interesting. I didn’t say that using a domain model automatically solves this problem. Rather, I described how each client could send a specific message, one a ChangeMaritalStatusMessage, the other a ChangeAddressMessage, to the server – in essence, giving the server the context in which each bit of data is relevant. The server could just open a transaction, get the customer object based on its Id, call a method on the customer (ChangeMaritalStatus or ChangeAddress), and commit the transaction. If two of these messages got to the server at the same time, the transactions would just cause them to be performed serially, and both transactions would succeed. The important part here is not losing the context of the changes.</p>
<p>When we talked about querying/reporting, things seemed quite a bit clearer. Datasets, or rather datatables seemed like a fine solution – most 3rd party controls support them out of the box. One guy mentioned that datasets performed poorly for large sets of data and that by designing custom entities for the result set, he could improve performance and memory utilization by, like, 70%. To tell you the truth, I think that if you need the performance, do it, if not, just use datasets. There isn’t much of an issue of correctness.</p>
<p>Just as an ending comment, in response to something someone said about <a href="http://udidahan.weblogs.us/category/scalability/">scalability</a>, I asked if they were reporting against the live OLTP data. The response was “yes”. Well, there’s a database scalability problem if I ever saw one. OLTP works most correctly when employing transactions that have an isolation level of serializable. The problem with them is that they lock up the whole table, or get blocked when a table scan is going on. Querying often results in a table scan. You can see the problem. Anyway, a common solution to this problem is to just reduce the isolation level, a quick fix that improves performance almost immediately. You take one hit in that your reports may be showing incorrect data, especially if they do aggregate type work. You might take another hit if your OLTP transactions need to do aggregate type work themselves. That second hit is pretty much unacceptable. A different solution is to accept the fact that the heaviest querying can usually show data that isn’t up to date up to the second.</p>
<p>In such a solution, you would have another database for reporting. It wouldn’t be just a replica of the OLTP database, but rather a lot more denormalized – which is a really not nice way of saying designed for reporting. You could then move the data from your OLTP database to the reporting database in some way (more to come on this topic) and you increase the scalability of your database. Just to define that a bit better – your OLTP database will be able to handle more transactions per unit of time, and reports will run faster, meaning that you will both improve their latency and the number of queries that can be handled per unit of time.</p>
<p>Anyway, I was pretty tired after all that, but if I had to sum it up I’d say something like this: before debating solutions, define the problem, you get a lot more insight into the solutions and you get it faster. That’s just win-win all around.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/11/09/dataset-%e2%80%93-or-mapping-rumble-at-teched-mvp-dinner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To map, or not to map?</title>
		<link>http://www.udidahan.com/2006/03/11/to-map-or-not-to-map/</link>
		<comments>http://www.udidahan.com/2006/03/11/to-map-or-not-to-map/#comments</comments>
		<pubDate>Sun, 12 Mar 2006 04:22:00 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[OO]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/267</guid>
		<description><![CDATA[I had this discussion with Clemens when he was last here in Israel - his position, as was so eloquently stated <a href="http://friends.newtelligence.net/clemensv/CommentView,guid,0fbf07a9-9e7a-4db4-a305-58250ac57a73.aspx">here</a>, was against, while I was pro. The question he raised "To map, or not to map?" he himself answered, "to map". The question remaining was how to map; write the sql yourself, or let some tool write/generate it for you.
<br/><br/>
The overarching question is: what do you REALLY gain by O/R mapping?
<br/><br/>
(As an aside, among the comments of his post are those using the acronym ORM. Please stop - that acronym is already taken by Object Role Modeling.)
<br/><br/>
I've been using O/R mapping techniques on mission critical projects for some time now, and if I wanted to compare it to what I did before, it would not be to writing all the sql by hand. I don't remember ever doing that - there was always code generation involved. Because, let's face it - there's a lot of drudgery involved for things that aren't performance critical. No reason to do THAT by hand.
<br/><br/>
So, for me, the ONE THING that O/R mapping gives me better than what I did before is this:
<br/><br/>
O/R mapping gets me better object-oriented business logic.
<br/><br/>
That's it.
<br/><br/>
Like Clemens said, if you "don't know SQL and RDBMS technology in any reasonable depth", don't expect to get good performance. Obviously this is true for any technique. But I guess that empirically speaking, the percentage of people without said knowledge is larger in the group where you don't HAVE to write sql.
<br/><br/>
So, I'll bet you're asking yourself, "if that's all Udi gets from O/R mapping, why does he keep doing it?" Or maybe you're asking yourself "should I get a beer? This is getting long..."
<br/><br/>
The fact of the matter is that I don't know a better way to write business logic than by using OO techniques. I grant that data is important, but the reason that many applications are built is business logic - there's something that this new system can/should do, that the old systems couldn't (often using the same data).
<br/><br/>
If I could sum up my understanding of Clemens position, it would be this: 
<br/><br/>
A lot of developers probably aren't experienced, or knowledgeable enough the use O/R mapping well. Therefore writing the sql yourself is better.
<br/><br/>
While I agree with the first statement, and I think that the same could be said about communication, threading, .net and many other things, I don't think that the conclusion logically follows.
<br/><br/>
So, I guess I would sum up my position like this:
<br/><br/>
If you would like to develop a persistent domain model, O/R mapping techniques will probably help you. If you would like your solution to perform well, you should probably learn how databases work, as well as what the O/R mapping tool does under the covers.]]></description>
			<content:encoded><![CDATA[<p>I had this discussion with Clemens when he was last here in Israel &#8211; his position, as was so eloquently stated <a href="http://friends.newtelligence.net/clemensv/CommentView,guid,0fbf07a9-9e7a-4db4-a305-58250ac57a73.aspx">here</a>, was against, while I was pro. The question he raised &#8220;To map, or not to map?&#8221; he himself answered, &#8220;to map&#8221;. The question remaining was how to map; write the sql yourself, or let some tool write/generate it for you.</p>
<p>The overarching question is: what do you REALLY gain by O/R mapping?</p>
<p>(As an aside, among the comments of his post are those using the acronym ORM. Please stop &#8211; that acronym is already taken by Object Role Modeling.)</p>
<p>I&#8217;ve been using O/R mapping techniques on mission critical projects for some time now, and if I wanted to compare it to what I did before, it would not be to writing all the sql by hand. I don&#8217;t remember ever doing that &#8211; there was always code generation involved. Because, let&#8217;s face it &#8211; there&#8217;s a lot of drudgery involved for things that aren&#8217;t performance critical. No reason to do THAT by hand.</p>
<p>So, for me, the ONE THING that O/R mapping gives me better than what I did before is this:</p>
<p>O/R mapping gets me better object-oriented business logic.</p>
<p>That&#8217;s it.</p>
<p>Like Clemens said, if you &#8220;don&#8217;t know SQL and RDBMS technology in any reasonable depth&#8221;, don&#8217;t expect to get good performance. Obviously this is true for any technique. But I guess that empirically speaking, the percentage of people without said knowledge is larger in the group where you don&#8217;t HAVE to write sql.</p>
<p>So, I&#8217;ll bet you&#8217;re asking yourself, &#8220;if that&#8217;s all Udi gets from O/R mapping, why does he keep doing it?&#8221; Or maybe you&#8217;re asking yourself &#8220;should I get a beer? This is getting long&#8230;&#8221;</p>
<p>The fact of the matter is that I don&#8217;t know a better way to write business logic than by using OO techniques. I grant that data is important, but the reason that many applications are built is business logic &#8211; there&#8217;s something that this new system can/should do, that the old systems couldn&#8217;t (often using the same data).</p>
<p>If I could sum up my understanding of Clemens position, it would be this: </p>
<p>A lot of developers probably aren&#8217;t experienced, or knowledgeable enough the use O/R mapping well. Therefore writing the sql yourself is better.</p>
<p>While I agree with the first statement, and I think that the same could be said about communication, threading, .net and many other things, I don&#8217;t think that the conclusion logically follows.</p>
<p>So, I guess I would sum up my position like this:</p>
<p>If you would like to develop a persistent domain model, O/R mapping techniques will probably help you. If you would like your solution to perform well, you should probably learn how databases work, as well as what the O/R mapping tool does under the covers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2006/03/11/to-map-or-not-to-map/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Uniqueness across the world</title>
		<link>http://www.udidahan.com/2004/07/31/uniqueness-across-the-world/</link>
		<comments>http://www.udidahan.com/2004/07/31/uniqueness-across-the-world/#comments</comments>
		<pubDate>Sun, 01 Aug 2004 04:53:51 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/108</guid>
		<description><![CDATA[Roy talks about the &#8220;The SQL Server usability advantage&#8221;, and begins to rumble with the Oracle zealots.
I just wanted to answer the question he asked in his post &#8220;BTW: one thing I&#8217;d really like in SQL server that I know Oracle has: Identities that are unique across multiple tables (I can&#8217;t remember the right word [...]]]></description>
			<content:encoded><![CDATA[<p>Roy talks about the <a href="http://weblogs.asp.net/rosherove/archive/2004/07/30/201118.aspx#FeedBack">&#8220;The SQL Server usability advantage&#8221;</a>, and begins to rumble with the Oracle zealots.</p>
<p>I just wanted to answer the question he asked in his post &#8220;BTW: one thing I&#8217;d really like in SQL server that I know Oracle has: Identities that are unique across multiple tables (I can&#8217;t remember the right word for that now ).&#8221; &#8211; why not just use GUIDs? There&#8217;s really great support for them in Sql 2k and in .net &#8211; and you get uniqueness not only across tables in a single DB, but globally (at least as close as you can do it today).</p>
<p>Just have as your primary key a column of type &#8220;uniqueidentifier&#8221; and give it a default value of NEWID() &#8211; this will take the column behaviour quite similar to IDENTITY &#8211; you don&#8217;t have to fill it in your code. When you need to take the data from the DB and into a data structure in your code, be it a dataset or custom class, all you need is System.Guid (a struct).</p>
<p>I&#8217;ve done some performance tests and it appears that guids are slower by a factor of 10-20% &#8211; but you do get global uniqueness, so it just might be worth the price, especially if you need replication capabilities. These numbers, of course, are by no means a valid benchmark. I suggest checking for yourself under loads that simulate your production environment.</p>
<p>One thing to note, for best performance on retrieval, it makes sense to add an identity column, not as a part of the primary key, but rather as your clustered index &#8211; keep the &#8220;uniqueidentifier&#8221; column as a non-clustered index. This makes a big difference when it comes to insertion times.</p>
<p>I&#8217;ve met a lot of people who haven&#8217;t thought that using GUIDs was so easy, and were left to suffer through replication with IDENTITY columns. I think it might be soon that the IDENTITY column will be replaced as the defacto standard for primary keys in tables. If you know better, well, don&#8217;t hesitate to prove me wrong <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/07/31/uniqueness-across-the-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t try this at home</title>
		<link>http://www.udidahan.com/2004/06/11/dont-try-this-at-home/</link>
		<comments>http://www.udidahan.com/2004/06/11/dont-try-this-at-home/#comments</comments>
		<pubDate>Sat, 12 Jun 2004 05:46:58 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://wp_630.weblogs.us/archives/85</guid>
		<description><![CDATA[The post is a result of a&#160;yahoo search (people DO use Yahoo to search, apparently) for &#8220;how to serialize a datareader&#8221;. The searcher got here, but I&#8217;m pretty sure that they didn&#8217;t find the answer, seeing as I don&#8217;t usually delve to the technological depths.
But, because whenever I&#8217;m asked a question I can&#8217;t answer, I [...]]]></description>
			<content:encoded><![CDATA[<p><P>The post is a result of a&nbsp;yahoo search (people DO use Yahoo to search, apparently) for &#8220;how to serialize a datareader&#8221;. The searcher got here, but I&#8217;m pretty sure that they didn&#8217;t find the answer, seeing as I don&#8217;t usually delve to the technological depths.</P><br />
<P>But, because whenever I&#8217;m asked a question I can&#8217;t answer, I go find the answer, I thought I might as well have this blog do the same.</P><br />
<P>The answer to the question &#8220;how to serialize a datareader&#8221; is:</P><br />
<P>You can&#8217;t, although if you try hard enough I&#8217;m sure you&#8217;ll find a way, but you really shouldn&#8217;t.</P><br />
<P>The reason is quite simple. </P><br />
<P>1. The datareader is connected to your database. Unlike the dataset which holds a copy of the data, disconnected from your database, the datareader uses up database resources as long as you use it.</P><br />
<P>2. If you want to serialize the datareader you got back from calling ExecuteReader on a Command object, it probably means you need to pass it far, far away &#8211; at best, a different process, at worst, a different machine. Just think about how much longer it takes to make inter-process or inter-machine calls than normal in-process calls. It takes orders of magnitude longer.</P><br />
<P>3. (1+2) Do you really want to be taking up database resources for that long ? Probably not, it will so adversely affect the scalability of your system that no amount of tweaking will help.</P><br />
<P>So, only use datareaders for quickly getting data out of the database, in-process. If you want to pass the data to anyone else, make a copy of it. A dataset acts as a decent representation of the data. Personally, I prefer to loop over the rows in a datareader, making an entity object (like Customer) out of each row, and adding it to an entity collection (like CustomerCollection), and then passing that to whoever needs it.</P><br />
<P>To sum up, if .Net doesn&#8217;t provide you with something you think you need, AND, you don&#8217;t really understand .Net that well, it probably means you shouldn&#8217;t be trying to do it. Although that&#8217;s something of an over-generalizing-bordering-on-patronizing statement, I hope you won&#8217;t take it the wrong way and realize that the guys at Microsoft did put in a lot of thought on this platform, and if mistakes were made, then they&#8217;re trying to fix them as we speak. So, although it may feel a little awkward, try to adjust your way of work to the way that the platform guides you. (Yes, I realize that I don&#8217;t follow my own advice, but that&#8217;s only because I&#8217;ve found a <EM>better</EM> way <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  )</P></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2004/06/11/dont-try-this-at-home/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

