<?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>I-D Media London Blog &#187; database</title>
	<atom:link href="http://blog.i-dmedialondon.co.uk/tag/database/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.i-dmedialondon.co.uk</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 09 Jul 2010 12:12:06 +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>Bridging the gap between the domain model and relational data</title>
		<link>http://blog.i-dmedialondon.co.uk/2009/08/bridging-the-gap-between-the-domain-model-and-relational-data/</link>
		<comments>http://blog.i-dmedialondon.co.uk/2009/08/bridging-the-gap-between-the-domain-model-and-relational-data/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 11:26:56 +0000</pubDate>
		<dc:creator>Gareth</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[nhibernate]]></category>
		<category><![CDATA[orm]]></category>

		<guid isPermaLink="false">http://blog.i-dmedialondon.co.uk/?p=82</guid>
		<description><![CDATA[Ever since the birth of the object-oriented design paradigm in software development, there has been the issue of how to store object data within the constraints of a relational database. Object associations and relations do not match very nicely with standard relational models (tables, columns, rows), and a lot of time is spent trying to [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since the birth of the object-oriented design paradigm in software development, there has been the issue of how to store object data within the constraints of a relational database. Object associations and relations do not match very nicely with standard relational models (tables, columns, rows), and a lot of time is spent trying to store and retrieve data to/from relational databases. Basically, it&#8217;s like trying to fit square blocks into round holes. It can be done eventually, but with lots of banging and swearing.</p>
<p>The accepted standard (until recently) would be to have some intermediate data access layer that would populate each field of an object with the column of data in a table. It would also take care of populating any associations of the object by querying the database on that object&#8217;s key, and populating the list. All of this would require a lot of scaffolding code to be written, as well as stored procedures, to store and retrieve this data, resulting in a lot more development time. This practice is also heavily error-prone, as stored procedures are not compiled code and are highly prone to errors. On top of that, adding say, a new field, would require the field to be added to the table, then to the stored procedure (or many stored procedures – usually 1 per CRUD operation!), then to the object, then to the scaffolding code that populates the object data.</p>
<p>Sounds like a nightmare? It is. That&#8217;s where object-relational modelling (ORM) frameworks come to the rescue. They attempt to bridge the gap between the object domain and relational data world by “hiding” a lot of the work that needs to be done in order to persist an object domain model to a relational database. One of these (and one of the most popular) is NHibernate. Originally it was written for Java but has since been ported to be used with .NET and has grown in features and popularity. It is also open source, which means it can be used without having to pay any licensing fees.</p>
<p>The basic steps required to use an ORM like NHibernate are: design and code your domain model, write a set of “mapping” files to tell NHibernate how your objects are mapped to the tables in the database, and that is pretty much it! The framework contains many functions to allow the storage and retrieval of the object data without having to write a single stored procedure or SQL query. It does this by generating the required SQL on-the-fly in the background, and it does quite efficiently as well. And don&#8217;t worry – it uses parameterised queries, so the code is not susceptible to SQL injection attacks.</p>
<p>If this sounds like a dream come true, well, it pretty much is. Don&#8217;t get me wrong – it has its own pitfalls, but generally, the time taken to get a basic data access layer up and running is pretty much halved. One of the most time-consuming tasks in this process is writing the mappings between the ORM and the database (usually a set of XML files), but this has also been alleviated via the introduction of Fluent NHibernate, which is a fluent extension of the mapping system. It allows type-safe compiled mapping to be written into the data access layer itself, and also includes a set of unit test extensions that can be used in units tests to ensure that the domain is correctly mapped to the database. “Fluent” relies heavily on lambda expressions for the mappings (introduced in .NET 3.0), so knowledge of these are essential. They&#8217;ve been around a while now, so if you&#8217;re not up with them, well, you better get cracking or you&#8217;ll be left behind!</p>
<p>More information about NHibernate and Fluent (and many other NHibernate libraries and extensions) can be found here: <a href="http://nhforge.org/" target="_blank">http://nhforge.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.i-dmedialondon.co.uk/2009/08/bridging-the-gap-between-the-domain-model-and-relational-data/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
