<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>From The Depths : Object-Relational Mapping</title><link>http://blogs.msdn.com/mthalman/archive/tags/Object-Relational+Mapping/default.aspx</link><description>Tags: Object-Relational Mapping</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Metadata Mapping in O-R Mapping Technology</title><link>http://blogs.msdn.com/mthalman/archive/2004/02/25/80022.aspx</link><pubDate>Wed, 25 Feb 2004 23:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:80022</guid><dc:creator>mthalman</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/mthalman/comments/80022.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mthalman/commentrss.aspx?PostID=80022</wfw:commentRss><description>&lt;P&gt;In my previous post I described the benefits of using Object-Relational Mapping (O-R Mapping) technology in regards to the encapsulation of change.&amp;nbsp; In this post and several subsequent posts I'm going to delve into some of the basic designs used in O-R Mapping technology.&amp;nbsp; The first deals with the actual mechanism of mapping&amp;nbsp;objects to relational tables and object fields to table columns.&amp;nbsp; Most commercial O-R Mapping products use metadata mapping as the mechanism that describes the relationship between an object and its data source so this is what I will focus on in this post.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Metadata mapping involves a developer defining mappings between an object and its data source in some static form separate from the code which processes that metadata to produce CRUD operations.&amp;nbsp; The form in which this metadata can be stored could be XML, a database, or even directly within source code.&amp;nbsp; The inherent hierarchical structure and non-compiled nature of XML lends itself to be the most useful of these forms.&amp;nbsp; A convenient method of using XML is to create your mappings through source code using a set of APIs which creates a map object of the same type that is used by the system which consumes the metadata.&amp;nbsp; The object is serialized to XML when creating the mappings then deserialized by the system when it needs to read the XML.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The more functionality supported by the O-R Mapping technology, the more complex the metadata mapping structure.&amp;nbsp; For example, if the O-R Mapping technology supports inheritance in its objects, there needs to be a way to express the inheritance in the metadata mapping.&amp;nbsp; Obviously, commercial O-R Mapping products aim to have significant functionality causing the metadata mapping to be quite complex.&amp;nbsp; Because of this mapping tools are developed to generate these metadata mappings.&amp;nbsp; This allows the developer to work through a&amp;nbsp;UI rather than manipulating whichever underlying form was chosen for the metadata mapping.&lt;/P&gt;
&lt;P&gt;Mapping is one of the first things focused on when developing an O-R Mapping product.&amp;nbsp; The information contained in the metadata will most likely change over time during development as more edge cases are found.&amp;nbsp; It is important to focus on developing a robust design in the metadata as a lot of change occurring in this area causes churn due to alterations of the old mappings in order to reflect the new design.&lt;/P&gt;
&lt;P&gt;In my next post I will describe the different methods of mapping inheritance hierarchies in a relational data source.&lt;/P&gt;
&lt;P&gt;Final thought:&lt;BR&gt;&lt;EM&gt;You are only as good as your metadata.&lt;/EM&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=80022" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mthalman/archive/tags/Object-Relational+Mapping/default.aspx">Object-Relational Mapping</category></item><item><title>Object-Relational Mapping Systems Encapsulate Change</title><link>http://blogs.msdn.com/mthalman/archive/2004/02/20/77315.aspx</link><pubDate>Fri, 20 Feb 2004 23:02:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:77315</guid><dc:creator>mthalman</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mthalman/comments/77315.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mthalman/commentrss.aspx?PostID=77315</wfw:commentRss><description>&lt;P&gt;Why have an object-relational mapping (ORM)&amp;nbsp;system?&amp;nbsp; Because change happens.&amp;nbsp; There's no getting around it.&amp;nbsp; I'll concede that ORM would not be necessary if you built a piece of software or data source which never had to be updated, extended, customized, upgraded,&amp;nbsp;or have a new technology&amp;nbsp;adopted.&amp;nbsp; Such a piece of software, of course, wouldn't last too long.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;At its core,&amp;nbsp;ORM is a separation of concerns in relation to the application that uses it.&amp;nbsp; The application programmer need only be concerned with objects while the ORM is concerned with how the objects relate to the data source.&amp;nbsp; I'd like to go through each of the points raised above and explain how&amp;nbsp;an object-relational mapping system solves these issues.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Updating&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;ORM encapsulates changes in the data source.&amp;nbsp; In order to improve data source performance, a developer may wish to consolidate the sources of a particular inheritance hierarchy into one source.&amp;nbsp; (I'll deal with the different ways of mapping a class inheritance hierarchy to data source in a later post.)&amp;nbsp; This change can be made within the ORM without effecting the code&amp;nbsp;or functionality of the application whatsoever.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Extending/Customizing&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I view &lt;EM&gt;extending&lt;/EM&gt; functionality to be an internal practice and &lt;EM&gt;customizing&lt;/EM&gt; functionality to be a practice done externally.&amp;nbsp; Essentially, ORM effects them in the same way by isolating the changes that need to be made.&amp;nbsp; Of course, enabling external customization has some extra infrastructure involved, but this is separate from the discussion of ORM.&amp;nbsp; Classes can be added to an existing inheritance hierarchy without effecting existing application code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Upgrading&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Upgrading to a new version of a data source has the potential for breaking changes to occur.&amp;nbsp; By encapsulating the communication with the data source in ORM, the breaking changes will not spread to application code.&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;New Technology&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;New features in a data source can be utilized more effectively by hiding their&amp;nbsp;interfaces from application code with ORM.&amp;nbsp; For example, the next version of SQL Server, code-named &amp;#8220;Yukon&amp;#8221;, allows you to use CLR-defined objects in SQL Server through enhanced functionality of &lt;A href="http://msdn.microsoft.com/msdnmag/issues/04/02/UDTsinYukon/"&gt;UDTs&lt;/A&gt;.&amp;nbsp; The new syntax used to manipulate these UDTs can be completely hidden with ORM and never exposed to application code.&amp;nbsp; This allows modifications to be made by ORM developers without impacting higher layers.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;It can be seen that ORM encapsulates the change that occurs when dealing with such a dynamic system as the data source.&amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=77315" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mthalman/archive/tags/Object-Relational+Mapping/default.aspx">Object-Relational Mapping</category></item></channel></rss>