[Edit: Reformatted code snippets and removed unnecessary line breaks]

Recently Oren (Ayende) had a serious of posts on NHibernate mappings and the various options you can configure using Xml mappings. This series of posts takes those examples and shows how you can use FluentNHibernate to configure the same mappings.

This is a companion post for Oren’s post on <component> mappings in NHibernate, here. I recommend reading his post before venturing forward.

In this post I’ll show how you use FluentNHibernate instead of using NHibernate’s xml mapping files.

Based on Oren’s original post on <component> mapping, here is the full mapping file:

<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>

Below are the mappings in FluentNHibernate:

Component(prop => prop.Address, mapping =>

{

     mapping.Map(prop => prop.StreetAddress1);

     mapping.Map(prop => prop.StreetAddress2);

     mapping.Map(prop => prop.City);

     mapping.Map(prop => prop.State);

     mapping.Map(prop => prop.ZipCode);

});

Basically the Component method allows you to specify which property in your entity is treated as a Component and then allow to provide mappings for the properties of the component itself.

Posted on Wednesday, May 13, 2009 10:33 AM | Filed Under [ NHibernate FluentNHibernate ]


Comments

Gravatar
# great
Posted by UGG outlet
on 10/12/2011 4:36 AM
very good post, thanks
Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 5 and 3 and type the answer here: