<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://devlicio.us/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Tim Barcz : NHibernate</title><link>http://devlicio.us/blogs/tim_barcz/archive/tags/NHibernate/default.aspx</link><description>Tags: NHibernate</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP1 (Build: 31106.3070)</generator><item><title>The Database Doesn't Matter or Don't Pollute Your Domain</title><link>http://devlicio.us/blogs/tim_barcz/archive/2009/07/15/the-database-doesn-t-matter-or-don-t-pollute-your-domain.aspx</link><pubDate>Thu, 16 Jul 2009 03:01:00 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:49406</guid><dc:creator>Tim Barcz</dc:creator><slash:comments>14</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/tim_barcz/rsscomments.aspx?PostID=49406</wfw:commentRss><comments>http://devlicio.us/blogs/tim_barcz/archive/2009/07/15/the-database-doesn-t-matter-or-don-t-pollute-your-domain.aspx#comments</comments><description>&lt;p&gt;Last week I spoke at &lt;a href="http://www.crineta.org"&gt;CRineta&lt;/a&gt; (Cedar Rapids Ineta) on &lt;a href="http://www.hibernate.org"&gt;NHibernate&lt;/a&gt;.&amp;nbsp; It was an introductory topic on NHibernate and as such I talk a bit about persistence and what it is. I find that it is worth defining persistence because, while it exists in most/all applications, many of us view persistence so very differently...as I found out last week.&lt;/p&gt;
&lt;p&gt;I defined persistence (a la &lt;a href="http://www.manning.com/kuate/"&gt;NHibernate in Action&lt;/a&gt;) as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;Persistence allows an object to outlive the process or application that created it.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In my applications, I prefer the application to represent the real world concepts and have a very solid &amp;quot;domain&amp;quot;.&amp;nbsp; (note: that I hesitate to even use that word as it is so globally applied these days to mean just about anything.) When I presented this view in my talk it was received with some less the enthusiastic sentiment from a few in the crowd.&amp;nbsp; The primary complaint from the unimpressed in the crowd was that generally &amp;quot;the data is the backbone of the application&amp;quot; or &amp;quot;its all about the data&amp;quot;.&amp;nbsp; While it&amp;#39;s true that data is important, VERY important in fact, it shouldn&amp;#39;t be the primary driver of you application, the objects/concepts should be.&lt;/p&gt;
&lt;p&gt;Over the last few years I&amp;#39;ve been focusing on having a less data centric view of the applications I work on.&amp;nbsp; Instead focusing on objects and concepts and the needs of the application.&amp;nbsp; So far this view has yet to be a disservice to myself or the applications I work on. Most practically this means I don&amp;#39;t think about my C# objects in terms database tables and rows of a table.&amp;nbsp; In the easiest example I can give about deriving your domain from your database I share a problem found in LINQ to SQL.&amp;nbsp; If we were doing a blog application and wanted to use LINQ to SQL we&amp;#39;d have classes for blog, post, category.&amp;nbsp; What you would also have to add with LINQ to SQL is a PostCategory object, to represent the idea that a post can have multiple categories and a category can have multiple posts.&amp;nbsp; What&amp;#39;s a PostCategory?&amp;nbsp; There&amp;#39;s no such thing in the real world.&amp;nbsp; A post has categories.&amp;nbsp; A category has posts.&amp;nbsp; PostCategory is not a real object.&amp;nbsp; &lt;b&gt;LINQ to SQL causes your domain model to suffer in order to achieve persistence.&lt;/b&gt; (Note: there may be a more elegant solution to solving this problem as we abandoned LINQ to SQL within days of discovering this.)&lt;/p&gt;
&lt;p&gt;There is no usefulness in just &amp;quot;having data&amp;quot;.&amp;nbsp; Therefore instead of speaking in terms of tables, rows, and columns, we should instead talk about objects and their interactions.&amp;nbsp; For example a row in a table most always represents some idea represented in software, a users account information, an order with products purchased.&amp;nbsp; Those pieces of information exist so that they can be retrieved at a later date and operated upon in some fashion (see the definition of persistence above). For the user it means being able to log in.&amp;nbsp; For the order it means displaying an status, invoicing, fulfillment, whatever.&amp;nbsp; The data stored in a database almost always represents some notion of &amp;quot;something&amp;quot; (sorry to be vague here), so let&amp;#39;s talk about that &amp;quot;something&amp;quot; and NOT the data.&lt;/p&gt;
&lt;p&gt;Should the database be optimized? Absolutely. Should the database be indexed and placed in the proper file group to achieve best performance? Absolutely. The database specific concepts however should never bleed into you application code.&amp;nbsp; If they do, you&amp;#39;re polluting you application/domain and working against the long term health of you project.&lt;/p&gt;
&lt;p&gt;In closing, I ultimately wasn&amp;#39;t surprised I was met with skepticism. It&amp;#39;s a long held view by many developers and is supported heavily by the Microsoft tooling.&amp;nbsp; It won&amp;#39;t change tomorrow or the next day.&amp;nbsp; It will change slowly over time one developer at a time.&amp;nbsp; Ask yourself, when you open a new application are you thinking databases? Columns? Indexes? Do you need to change how you think about your application?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=49406" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/NHibernate/default.aspx">NHibernate</category></item><item><title>NHProfiler - An Early Look</title><link>http://devlicio.us/blogs/tim_barcz/archive/2008/12/09/nhprofiler-an-early-look.aspx</link><pubDate>Tue, 09 Dec 2008 07:09:17 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:43347</guid><dc:creator>Tim Barcz</dc:creator><slash:comments>16</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/tim_barcz/rsscomments.aspx?PostID=43347</wfw:commentRss><comments>http://devlicio.us/blogs/tim_barcz/archive/2008/12/09/nhprofiler-an-early-look.aspx#comments</comments><description>&lt;p&gt;&lt;img src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/NHProfWhatistheroleoftheDBA_DB9/Icon_thumb.png" align="right" alt="" /&gt; Over the past week I&amp;#39;ve had the distinct opportunity to have a first-hand look into &lt;a href="http://ayende.com/Blog/archive/2008/10/13/nhprof-another-milestone.aspx"&gt;NHProf&lt;/a&gt;, &lt;a href="http://www.ayende.com/blog/"&gt;Ayende&amp;#39;s&lt;/a&gt; upcoming profiler for &lt;a href="http://www.hibernate.org/343.html"&gt;NHibernate&lt;/a&gt;.&amp;#160; It&amp;#39;s been an honor to be part of the team that is putting NHProfiler through its paces.&amp;#160; While NHProfiler is still in private beta it is very impressive and I want to let you peek inside.&lt;/p&gt;  &lt;p&gt;This evening I decided to sit down and spend some time poking around an application and watch NHProfiler to see if anything seemed out of sorts.&amp;#160; Here&amp;#39;s what I found:&lt;/p&gt;  &lt;h2&gt;Easy To Understand&lt;/h2&gt;  &lt;p&gt;You can get by without purchasing NHProf, from what I see there&amp;#39;s nothing you can&amp;#39;t &amp;quot;figure out&amp;quot; yourself.&amp;#160; NHProf is a lot like &lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; or &lt;a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/"&gt;CodeRush&lt;/a&gt;, you can get by without it, but why would you want to?&amp;#160; Here&amp;#39;s what I mean, you can pop open SQL Server Profiler and see what is being executed:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image7.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="412" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image7_5F00_thumb.png" width="575" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;That&amp;#39;s messy but take a look at how NHProf collates the data:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image3.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="381" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image3_5F00_thumb.png" width="249" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Relevant&lt;/h2&gt;  &lt;p&gt;You can sift through the SQL Server Profiler trace if you&amp;#39;d like to but NHProfiler does a great job in giving you the same information, just presented better.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image11.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="578" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image11_5F00_thumb.png" width="578" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;From this view I can see that five queries were run and I can see that three of the same queries are being issued which might point to an area where there is some tweaking to do.&lt;/p&gt;  &lt;h2&gt;Performance Gains&lt;/h2&gt;  &lt;p&gt;We all want our applications to run faster.&amp;#160; We want speed and performance but often times its takes quite a bit of time to find performance problems and their subsequent fixes.&amp;#160; NHProfiler allowed me to very quickly find some queries that didn&amp;#39;t need to be executing and tweak some code to eliminate those calls.&amp;#160; Since I can see the code that &lt;a href="http://www.hibernate.org/362.html"&gt;NHibernate&lt;/a&gt; generates I can also make modifications to query I&amp;#39;m submitting to &lt;a href="http://www.hibernate.org/362.html"&gt;NHibernate&lt;/a&gt; for further performance gains.&lt;/p&gt;  &lt;p&gt;In a very short amount of time (the writing of this blog post has taken several times longer) I was able to reduce reduce data access time by a factor of nearly 10.&amp;#160; How do I know that, I have the hard data to prove it.&lt;/p&gt;  &lt;h3&gt;Before:&lt;/h3&gt;  &lt;h2&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image15.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="124" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image15_5F00_thumb.png" width="337" border="0" /&gt;&lt;/a&gt;&lt;/h2&gt;  &lt;h3&gt;After:&lt;/h3&gt;  &lt;p&gt;&lt;a href="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image19.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="114" alt="image" src="http://devlicio.us/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/tim_5F00_barcz/image19_5F00_thumb.png" width="314" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;h2&gt;Conclusion&lt;/h2&gt;  &lt;p&gt;If you use NHibernate, NHProfiler is a must.&amp;#160; By using NHProf to observe my applications I&amp;#39;m able to save my time and not have to burrow through SQL Server Profiler or wonder what is going on at the data level.&amp;#160; I am quickly able to observe what is going on and when and make any necessary modification and then observe the outcome.&amp;#160; While you can use Visual Studio without &lt;a href="http://www.jetbrains.com/resharper/"&gt;ReSharper&lt;/a&gt; or &lt;a href="http://devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/"&gt;CodeRush&lt;/a&gt; many of you out there have found you just don&amp;#39;t want to.&amp;#160; After using these productivity tools you find that you&amp;#39;re able to work with less friction.&amp;#160; NHProfiler is the same way, you can work without it, but I highly recommend against it.&lt;/p&gt;  &lt;p&gt;Keep your eye on &lt;a href="http://www.ayende.com/blog/"&gt;Ayende&amp;#39;s blog&lt;/a&gt; for information coming soon.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=43347" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/NHProf/default.aspx">NHProf</category><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/Tools/default.aspx">Tools</category></item><item><title>Alt.NET Austin - Workshops Day 1</title><link>http://devlicio.us/blogs/tim_barcz/archive/2008/11/01/alt-net-austin-workshops-day-1.aspx</link><pubDate>Sat, 01 Nov 2008 06:17:40 GMT</pubDate><guid isPermaLink="false">40756a8b-6212-4073-9d98-6c26781577de:42843</guid><dc:creator>Tim Barcz</dc:creator><slash:comments>15</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://devlicio.us/blogs/tim_barcz/rsscomments.aspx?PostID=42843</wfw:commentRss><comments>http://devlicio.us/blogs/tim_barcz/archive/2008/11/01/alt-net-austin-workshops-day-1.aspx#comments</comments><description>&lt;p&gt;I&amp;#39;m in Austin, Texas for the &lt;a href="http://www.kaizenconf.com/"&gt;Kaizen Continuous Improvement Conference&lt;/a&gt; this weekend.&amp;#160; One of the very cool things the organizers did for this event was offer two days of workshops before the conference.&amp;#160; While I&amp;#39;m excited for the conference itself, much of my excitement for the conference stemmed from these pre-conference workshops.&amp;#160; Yesterday I went to two workshops, both of which should be online at some point.&lt;/p&gt;  &lt;h2&gt;Advanced NHibernate - with Ayende Rahien&lt;/h2&gt;  &lt;p&gt;I was a little leery of this one given our seemingly trivial usage of &lt;a href="http://www.hibernate.org/343.html"&gt;NHibernate&lt;/a&gt;.&amp;#160; I was pleasantly surprised to see how much of this was perfectly timed for where we are at.&amp;#160; Oren went into great detail on various parts of the NHibernate and it&amp;#39;s contributing projects.&amp;#160; He spoke a bit on caching and performance optimizations/pitfalls that you generally have to watch out for.&amp;#160; Quite possibly the coolest feature was getting to see &lt;a href="http://ayende.com/Blog/archive/2008/10/29/nh-prof-teaser.aspx"&gt;NHibernate profiling application&lt;/a&gt; that Oren is working on.&amp;#160; This won&amp;#39;t be a free tool but the price from what I&amp;#39;ve heard from Oren will be very reasonable (I am not saying the price since it may change).&amp;#160; With NHProfiler you can see all the queries that get executed from you application.&amp;#160; It even has alerts built in, such that if it detects a problem (ie. Select N+1) it will let you know.&amp;#160; Without hesitation, if you&amp;#39;re using NHibernate, buy NHProfiler when it comes out, it is easily worth it.&lt;/p&gt;  &lt;p&gt;The most important concept that I got from this session is how powerful NHibernate is.&amp;#160; People can fight ORM, roll their own solution, or write their own T-SQL but when you see what NHibernate has to offer it seems ridiculous to choose any of those options.&amp;#160; Two little known NHibernate features you may not have known about that I&amp;#39;ve found very cool:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;NHibernate Search : Leverages the open source &lt;a href="http://incubator.apache.org/lucene.net/"&gt;Lucene.NET&lt;/a&gt; implementation and keeps allows you to do search which have performed poorly in the database against a very fast Lucene index. &lt;/li&gt;    &lt;li&gt;NHibernate Shards : Written by Google this allows you to scale across a number of databases. I won&amp;#39;t delve into sharding here but you can read up on it on &lt;a href="http://en.wikipedia.org/wiki/Shard_(database_architecture)"&gt;wikipedia&lt;/a&gt;. &lt;/li&gt; &lt;/ul&gt;  &lt;h2&gt;DDD Chalk Talk - David Laribee&lt;/h2&gt;  &lt;p&gt;I was very interested in this chalk talk since the name seemed to indicate we&amp;#39;d get a chance to have an open discussion about DDD and how one would approach DDD in their domain.&amp;#160; This talk seemed to have peaks and valleys.&amp;#160; It was no fault of anyone in the talk, but DDD seems to be one of those topics where it becomes extremely tough to follow once you get outside of what you know.&amp;#160; The topic of aggregate roots and contexts were quite helpful.&amp;#160; I found it encouraging that ideas that I have interpreted from the book seem in line with what &lt;a href="http://codebetter.com/blogs/david_laribee/"&gt;David Laribee&lt;/a&gt; demonstrated on the white board.&amp;#160; I&amp;#39;m only a few chapters into the book and am absorbing as much of the DDD concepts from those who are ahead of me on this path.&amp;#160; I&amp;#39;m encouraged to see where others have taken it, the value they have found in it, and what it could mean for our application(s) in the future.&amp;#160; Just have to keep reading and learning.&lt;/p&gt;  &lt;p&gt;Quite a lot for only the first day of a multi-day conference.&amp;#160; For those of you who aren&amp;#39;t here in Austin but wish you were, keep an eye out for videos of the many presentations that my pop up.&amp;#160; I will update this blog if/when I see them appear online.&amp;#160; There was a lot of good content coming out of these workshops and it&amp;#39;d be a shame to have the content limited only to those in attendance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://devlicio.us/aggbug.aspx?PostID=42843" width="1" height="1"&gt;</description><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/DDD/default.aspx">DDD</category><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/NHibernate/default.aspx">NHibernate</category><category domain="http://devlicio.us/blogs/tim_barcz/archive/tags/Alt.NET/default.aspx">Alt.NET</category></item></channel></rss>