<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Felice Pollano Blog - Dapper</title>
    <link>http://www.felicepollano.com/</link>
    <description>The official Fatica Labs Blog!</description>
    <language>en-us</language>
    <copyright>Felice Pollano</copyright>
    <lastBuildDate>Thu, 12 Apr 2012 08:41:12 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>felice@felicepollano.com</managingEditor>
    <webMaster>felice@felicepollano.com</webMaster>
    <item>
      <trackback:ping>http://www.felicepollano.com/Trackback.aspx?guid=d0df046c-d902-44bb-922c-55c4856945df</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=d0df046c-d902-44bb-922c-55c4856945df</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=d0df046c-d902-44bb-922c-55c4856945df</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d0df046c-d902-44bb-922c-55c4856945df</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p align="justify">
There are scenarios in which <a href="http://nhforge.org" target="_blank">NHibernate</a> performance
decrease even if we do all the effort to correctly use it. This could happen if we
need in some circumstances to load a lot of record ( I explicitly use record instead
of ‘Entity’ ) from some relational structures, and doing this the <strong>OR/M</strong> way
means overload the session with a lot of entities, that is painful in term of speed.
Other cases happens when we need to  write or update something that is not properly
represented in the entity model we have, maybe because the model is more “read” oriented.
Other cases? I’m not able to grasp all  of course, but I’m sure that you face
some if you use an OR/M ( not necessarily NH ) in your daily basis. Using NHibernate
an alternative could be using <strong>FlushMode=Never</strong> in session, but you
still have all the OR/M plumbing in the hydrating entity code that negatively impacts
the performances. I obtained impressive results in solving such a situation, by using <a href="http://code.google.com/p/dapper-dot-net/" target="_blank">Dapper</a>,
a so called single file OR/M. It is a single file that provider some <strong>IDbConnection</strong> extension
methods, those methods works on an already opened connection, so we can use the connection
sticked to the NHibernate open session, as here below: 
</p>
        <pre lang="C#">// don't get confused by LinqToNh Query&lt;&gt; this one is the Dapper query
// acting on the CONNECTION :)

session.Connection.Query&lt;MyDto&gt;("select Name=t.Name,Mail=t.Mail from mytable t where t.Valid=@Valid",new{Valid=true});




</pre>
        <p>
you obtain back a big recordset of MyDto instances in almost the same time if you
wire by hand a DateReader vertical on the dto, with all the error checking. 
</p>
        <h1>
        </h1>
        <h5>So why don’t use it always?
</h5>
        <p>
Because despite the name Dapper is not an OR/M, it does not keep track of modified
entities, it does not help you in paginating results or lazy load the entity graph,
neither helps in porting from one SQL dialect to another. 
</p>
        <h6>
        </h6>
        <h5>Is this strategy used somewhere else?
</h5>
        <p>
You probably find interesting to read <a href="http://samsaffron.com/archive/2011/03/30/How+I+learned+to+stop+worrying+and+write+my+own+ORM" target="_blank">this
post</a> by <a href="http://samsaffron.com/" target="_blank">Sam Saffron</a>, this
solution is used in Stackoverflow.com combined with the LinqToSql OR/M to help when
the OR/M performance are not enough. 
</p>
        <p>
By my test I experienced a performance increase of <strong>10x</strong> in a very
hacking situation, but I can’t show the case since it is not public code. Something
more scientific about performance is <a href="http://code.google.com/p/dapper-dot-net/" target="_blank">here</a>. 
</p>
        <img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=d0df046c-d902-44bb-922c-55c4856945df" />
      </body>
      <title>NHibernate performance hacks</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=d0df046c-d902-44bb-922c-55c4856945df</guid>
      <link>http://www.felicepollano.com/2012/04/12/NHibernatePerformanceHacks.aspx</link>
      <pubDate>Thu, 12 Apr 2012 08:41:12 GMT</pubDate>
      <description>&lt;p align="justify"&gt;
There are scenarios in which &lt;a href="http://nhforge.org" target="_blank"&gt;NHibernate&lt;/a&gt; performance
decrease even if we do all the effort to correctly use it. This could happen if we
need in some circumstances to load a lot of record ( I explicitly use record instead
of ‘Entity’ ) from some relational structures, and doing this the &lt;strong&gt;OR/M&lt;/strong&gt; way
means overload the session with a lot of entities, that is painful in term of speed.
Other cases happens when we need to&amp;nbsp; write or update something that is not properly
represented in the entity model we have, maybe because the model is more “read” oriented.
Other cases? I’m not able to grasp all&amp;nbsp; of course, but I’m sure that you face
some if you use an OR/M ( not necessarily NH ) in your daily basis. Using NHibernate
an alternative could be using &lt;strong&gt;FlushMode=Never&lt;/strong&gt; in session, but you
still have all the OR/M plumbing in the hydrating entity code that negatively impacts
the performances. I obtained impressive results in solving such a situation, by using &lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;Dapper&lt;/a&gt;,
a so called single file OR/M. It is a single file that provider some &lt;strong&gt;IDbConnection&lt;/strong&gt; extension
methods, those methods works on an already opened connection, so we can use the connection
sticked to the NHibernate open session, as here below: 
&lt;/p&gt;
&lt;pre lang="C#"&gt;// don't get confused by LinqToNh Query&amp;lt;&amp;gt; this one is the Dapper query
// acting on the CONNECTION :)

session.Connection.Query&amp;lt;MyDto&amp;gt;("select Name=t.Name,Mail=t.Mail from mytable t where t.Valid=@Valid",new{Valid=true});




&lt;/pre&gt;
&lt;p&gt;
you obtain back a big recordset of MyDto instances in almost the same time if you
wire by hand a DateReader vertical on the dto, with all the error checking. 
&lt;/p&gt;
&lt;h1&gt;
&lt;/h1&gt;
&lt;h5&gt;So why don’t use it always?
&lt;/h5&gt;
&lt;p&gt;
Because despite the name Dapper is not an OR/M, it does not keep track of modified
entities, it does not help you in paginating results or lazy load the entity graph,
neither helps in porting from one SQL dialect to another. 
&lt;/p&gt;
&lt;h6&gt;
&lt;/h6&gt;
&lt;h5&gt;Is this strategy used somewhere else?
&lt;/h5&gt;
&lt;p&gt;
You probably find interesting to read &lt;a href="http://samsaffron.com/archive/2011/03/30/How+I+learned+to+stop+worrying+and+write+my+own+ORM" target="_blank"&gt;this
post&lt;/a&gt; by &lt;a href="http://samsaffron.com/" target="_blank"&gt;Sam Saffron&lt;/a&gt;, this
solution is used in Stackoverflow.com combined with the LinqToSql OR/M to help when
the OR/M performance are not enough. 
&lt;/p&gt;
&lt;p&gt;
By my test I experienced a performance increase of &lt;strong&gt;10x&lt;/strong&gt; in a very
hacking situation, but I can’t show the case since it is not public code. Something
more scientific about performance is &lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;here&lt;/a&gt;. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=d0df046c-d902-44bb-922c-55c4856945df" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=d0df046c-d902-44bb-922c-55c4856945df</comments>
      <category>CodeProject</category>
      <category>Dapper</category>
      <category>NHibernate</category>
      <category>ORM</category>
    </item>
  </channel>
</rss>