The object-relational mapper for .NET

NHibernate Mapping - <dynamic-component/>

Like the <component/> mapping, <dynamic-component/> allows us to treat parts of the entity table in a special way. In this case, it allow us to push properties from the mapping into a dictionary, instead of having to have the entity have properties for it.

This is very useful when we need to build dynamically extended entities, where the client can add columns on the fly.

Let us take this entity as an example:

And this table:


Where we want to have the SSN accessible from our entity, but without modifying its structure. We can do this using <dynamic-component/>:

<class name="Person"

	<id name="Id">
		<generator class="identity"/>
	<property name="Name" />

	<dynamic-component name="Attributes">
		<property name="SSN"

And the query just treat this as yet another column in the table:


Posted Fri, 10 April 2009 08:23:00 PM by Ayende
Filed under:

comments powered by Disqus
© NHibernate Community 2024