Nhibernate <component> tag - mapping multiple entity classes' fields with one table's columns

In short, mapping the properties of multiple entity classes to columns in one table.

Refer to  http://ayende.com/blog/3937/nhibernate-mapping-component

<component/> is an interesting feature of NHibernate, which map more or less directly into the notion of a Value Type in DDD. This is a way to create an object model with higher granularity than the physical data model.

And this object model:

They are quite different, where the physical data model put all the data in a single table, we want to treat them in our object model as two separate classes. This is where <component/> comes into play:

<class name="Person"
	table="People">

	<id name="Id">
		<generator class="identity"/>
	</id>
	<property name="Name" />
	<component name="Address">
		<property name="Line1"/>
		<property name="Line2"/>
		<property name="City"/>
		<property name="Country"/>
		<property name="ZipCode"/>
	</component>
</class>
posted @ 2012-08-30 16:13  webglcn  阅读(211)  评论(0编辑  收藏  举报