<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" 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:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>C#</title>
        <link>http://www.thorndycraft.net/blog/category/3.aspx</link>
        <description>C#</description>
        <language>en-US</language>
        <copyright>Jonathon Thorndycraft</copyright>
        <managingEditor>jthorndy@gmail.com</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <item>
            <title>ORMs and Doing the Right Thing</title>
            <link>http://thorndycraft.net/blog/archive/2008/02/18/orms-and-doing-the-right-thing.aspx</link>
            <description>&lt;p class="MsoNormal"&gt;As most developers do (I would hope) I think a lot about the best tools for getting my job done. I’ve been really interested in ORMs lately. Linq to SQL is really exciting. ActiveRecord is really easy to get working. Nhibernate seems to be the most full featured (as long as you don’t care about stored procedures). The Entity Framework seems like it might be the best of the bunch. But of course, there is always the option of doing data access the good old fashioned way with ADO.NET calls.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;So what’s the right tool for the job? Linq to SQL’s big advantage is Linq. ActiveRecord is really easy to use and more flexible when it comes to the types of relationships that it allows (basically, it allows many to many relationships). Nhibernate is very flexible and I understand Linq support has been added recently. Entity Framework, unfortunately, hasn’t actually been released.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;But Linq to SQL, ActiveRecord and NHibernate are all fairly similar. They allow you to map your database tables directly to objects. If your Customers table is related to your Orders table you can just add a collection of Orders to your Customer object and a Customer object to your Order object, and it works like magic. And all three of those technologies will produce nice clean SQL for accessing those two tables.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;But what happens when you go from a few tables to a few dozen tables? If you aren’t extremely careful when creating your objects you can find yourself in a performance nightmare. You get your Order object and that automatically gets your Customer object, which automatically gets your CustomerAddress object and your CustomerPreferences object. And the only data that you wanted to get was the Order itself.&lt;/p&gt;
&lt;p class="MsoNormal"&gt;So a fan of ORMs could argue that such a situation would only arise from poorly planning your objects. Fair enough. But here’s the problem I have with ORMs. It’s not just that it is possible to do things the wrong way and kill your performance. ORMs actually encourage you to do things this way. ORMs make it really easy to shoot yourself in the foot.&lt;strong style=""&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;This relates to something else I’ve been thinking about a lot lately. I frequently read &lt;a href="http://www.ayende.com/Blog/archive/2008/02/08/Dont-make-me-THINK.aspx"&gt;Ayende Rahien’s blog&lt;/a&gt; and he was talking about how a project should be setup so that it is easy for a developer to do the right thing. I think ORMs do the exact opposite. I’m starting to think that they make it too easy to do the wrong thing.&lt;/p&gt;&lt;img src="http://thorndycraft.net/blog/aggbug/2.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jonathon Thorndycraft</dc:creator>
            <guid>http://thorndycraft.net/blog/archive/2008/02/18/orms-and-doing-the-right-thing.aspx</guid>
            <pubDate>Tue, 19 Feb 2008 03:56:05 GMT</pubDate>
            <wfw:comment>http://thorndycraft.net/blog/comments/2.aspx</wfw:comment>
            <comments>http://thorndycraft.net/blog/archive/2008/02/18/orms-and-doing-the-right-thing.aspx#feedback</comments>
            <slash:comments>127</slash:comments>
            <wfw:commentRss>http://thorndycraft.net/blog/comments/commentRss/2.aspx</wfw:commentRss>
            <trackback:ping>http://thorndycraft.net/blog/services/trackbacks/2.aspx</trackback:ping>
        </item>
    </channel>
</rss>
