<?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 - ORM</title>
    <link>http://www.felicepollano.com/</link>
    <description>The official Fatica Labs Blog!</description>
    <language>en-us</language>
    <copyright>Felice Pollano</copyright>
    <lastBuildDate>Wed, 25 Jul 2012 10:32:20 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=5553ebb4-4490-436a-99f4-4855089b6921</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=5553ebb4-4490-436a-99f4-4855089b6921</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=5553ebb4-4490-436a-99f4-4855089b6921</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5553ebb4-4490-436a-99f4-4855089b6921</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>From NH to Dapper: what's missing from a fully fledged OR/M?</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=5553ebb4-4490-436a-99f4-4855089b6921</guid>
      <link>http://www.felicepollano.com/2012/07/25/FromNHToDapperWhatsMissingFromAFullyFledgedORM.aspx</link>
      <pubDate>Wed, 25 Jul 2012 10:32:20 GMT</pubDate>
      <description>&lt;p style="TEXT-ALIGN: justify"&gt;
I just did some new project at work with heavy and extensive usage of data access
over legacy databases, and I tried the &lt;a href="http://code.google.com/p/dapper-dot-net/"&gt;DapperDotNet&lt;/a&gt; micro
or/m instead of NHibernate. I just point before the fact that I've already all the
infrastructure to map such a legacy DB in NH by using mapping by code and leveraging
a lot of conventios in the DB table/field naming, so the mapping work does not make
any difference for me, a part the fact that it is not needed with dapper ( or at least,
not needed in the Entity based form ) since you just map the data transfer structures.
So what's missing from using NH? Lets see:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;strong&gt;Inheritance&lt;/strong&gt; I was a little worried
about Dapper leak of support for any kind of inheritance concept, but really I managed
to do all the requirement without it, &lt;a href="http://www.infoq.com/articles/ORM-Saffron-Conery"&gt;having
the best dsl for querying the database&lt;/a&gt; did the work.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;strong&gt;Identity Map&lt;/strong&gt; We have to keep an
eye to the fact the identity map does not exist anymore using a micro/orm. This not
just in subsequnt queries in the same section, but when we load associations, expecially
when the associated class has a lot of data. For example I had an association with
an entity containing a big bounch of xml, if I load that association in a dto, I need
to manage myself to load it just when the associated id changes.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;strong&gt;Lazy Collections&lt;/strong&gt; using Dapper we
have to forget such automatic features, basically there is not such a concept, but
I really can live without it.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;strong&gt;Db Schema Create/Update&lt;/strong&gt; I really
miss that just in unit testing. You have to craft the schema by hand in your unit
test. In production in my case I have no control for the schema generation *at all*
so it is not a problem anyway, but I guess the NH update / generation is not enough
for a real DB deployment. You probably need a DB migration in any case.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;strong&gt;Linq/Hql&lt;/strong&gt; In fact I miss LinqToNh.
Not absolutely Hql. But we have to consider that a big portion of the impedence an
OR/M introduces is caused to the creation of a DSL on top of plain SQL.
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify"&gt;
&lt;strong&gt;Let's consider the pure benefit we have from Dapper&lt;/strong&gt;:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;Any kind of optimized SQL is easy to submit.
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;Calling an SP handling In/out parametrs is simple
as calling a query
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;&lt;&gt; in NH )&lt;/div&gt;Multiple resultset are easy to handle
( The Future 
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;Bulk operations are easy too ( you still need real
bulk if you realaly want to insert big amount of data )
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;div style="TEXT-ALIGN: justify"&gt;Really noticeable increase in performance, due to
smart ADO.NET underlayng access and to the fact we control the SQL roundtrip ourself
)
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="TEXT-ALIGN: justify"&gt;
So in my opinion: we probably code a little more in the data access phase, but we
have more control, there is no a separate "mapping" part, that can be not so easy
to mantain, but it really worth the effort to &lt;strong&gt;move definitely&lt;/strong&gt; in
the &lt;strong&gt;Micro Orm&lt;/strong&gt; direction.
&lt;/p&gt;
&lt;p style="TEXT-ALIGN: justify"&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=5553ebb4-4490-436a-99f4-4855089b6921" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=5553ebb4-4490-436a-99f4-4855089b6921</comments>
      <category>C#</category>
      <category>NHibernate</category>
      <category>ORM</category>
    </item>
    <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>
    <item>
      <trackback:ping>http://www.felicepollano.com/Trackback.aspx?guid=c0846743-6509-4ad1-a268-96daa65710cc</trackback:ping>
      <pingback:server>http://www.felicepollano.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.felicepollano.com/PermaLink.aspx?guid=c0846743-6509-4ad1-a268-96daa65710cc</pingback:target>
      <dc:creator>Felice Pollano</dc:creator>
      <wfw:comment>http://www.felicepollano.com/CommentView.aspx?guid=c0846743-6509-4ad1-a268-96daa65710cc</wfw:comment>
      <wfw:commentRss>http://www.felicepollano.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c0846743-6509-4ad1-a268-96daa65710cc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In <a href="http://ayende.com/blog/136195/when-should-you-use-nhibernate" target="_blank">this
post</a> Ayende talk about when we should use <a href="http://nhforge.org" target="_blank">NHibernate</a> and
he point that in almost read only scenario other approach can be preferred. I think
he forget to mention the fact that even in such a scenario we can leverage a very
reliable multi DB abstraction offered by NH that can help us if we think to target
different data platforms. In order to me we should say that the point of decision
to choose fro NH to another approach is the ability to create an entity model, and
an entity model helpful to our objectives. This can also depends on how much we are
confortable with the technology. Another interesting extension of the argument is,
if we should not  use NH what can we use instead ? Well not for sure EF, since
the reason of renounce to NH in a project should be the same to avoid EF. The NOSql
solutions works only if we can completely avoid a relational database, and the pure
crude ADO.NET is just ugly. An option could be <a href="http://code.google.com/p/dapper-dot-net/" target="_blank">Dapper</a>, 
a lightweight OR/M ( not exactly an OR/M, but almost ) that remove all the ugliness
of ADO.NET and does not change the performance in comparison on using the manual data
access approach. I did not tried it myself, but one of its users is <a href="http://www.stackoverflow.com" target="_blank">stackoverlow</a>,
so this should be by itself a guarantee. 
</p>
        <img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=c0846743-6509-4ad1-a268-96daa65710cc" />
      </body>
      <title>A comment about using NHibernate</title>
      <guid isPermaLink="false">http://www.felicepollano.com/PermaLink.aspx?guid=c0846743-6509-4ad1-a268-96daa65710cc</guid>
      <link>http://www.felicepollano.com/2011/11/27/ACommentAboutUsingNHibernate.aspx</link>
      <pubDate>Sun, 27 Nov 2011 08:56:37 GMT</pubDate>
      <description>&lt;p&gt;
In &lt;a href="http://ayende.com/blog/136195/when-should-you-use-nhibernate" target="_blank"&gt;this
post&lt;/a&gt; Ayende talk about when we should use &lt;a href="http://nhforge.org" target="_blank"&gt;NHibernate&lt;/a&gt; and
he point that in almost read only scenario other approach can be preferred. I think
he forget to mention the fact that even in such a scenario we can leverage a very
reliable multi DB abstraction offered by NH that can help us if we think to target
different data platforms. In order to me we should say that the point of decision
to choose fro NH to another approach is the ability to create an entity model, and
an entity model helpful to our objectives. This can also depends on how much we are
confortable with the technology. Another interesting extension of the argument is,
if we should not&amp;nbsp; use NH what can we use instead ? Well not for sure EF, since
the reason of renounce to NH in a project should be the same to avoid EF. The NOSql
solutions works only if we can completely avoid a relational database, and the pure
crude ADO.NET is just ugly. An option could be &lt;a href="http://code.google.com/p/dapper-dot-net/" target="_blank"&gt;Dapper&lt;/a&gt;,&amp;nbsp;
a lightweight OR/M ( not exactly an OR/M, but almost ) that remove all the ugliness
of ADO.NET and does not change the performance in comparison on using the manual data
access approach. I did not tried it myself, but one of its users is &lt;a href="http://www.stackoverflow.com" target="_blank"&gt;stackoverlow&lt;/a&gt;,
so this should be by itself a guarantee. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.felicepollano.com/aggbug.ashx?id=c0846743-6509-4ad1-a268-96daa65710cc" /&gt;</description>
      <comments>http://www.felicepollano.com/CommentView.aspx?guid=c0846743-6509-4ad1-a268-96daa65710cc</comments>
      <category>CodeProject</category>
      <category>NHibernate</category>
      <category>ORM</category>
    </item>
  </channel>
</rss>