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 the <join> mapping in NHibernate, here. I recommend reading his post before venturing forward.

To create a joined table mapping using FluentNHibernate you need to use the WithTable mapping function and specify the JoinedPart definition:

WithTable("Addresses", join =>

                           {

                               join.Map(prop => prop.StreetAddress1, "StreetAddress1");

                            join.Map(prop => prop.StreetAddress2, "StreetAddress2");

                            join.Map(prop => prop.City, "City");

                            join.Map(prop => prop.State, "State");

                            join.Map(prop => prop.ZipCode, "ZipCode");

                               join.WithKeyColumn("PersonId");

                           });

The WithTable mapping function has two overloads, one just taking in a string parameter and another that takes in a string parameter as well as a action that allows you to configure a JoinPart. The first overload instructs fluent nhibernate to output the table name of the class being mapped, for e.g WithTable("Persons") will generate a mapping: <class name="Person" table="Persons"> element.

The second overload outputs the <join> element in the mapping. Just like mapping a component, the JoinPart allows you to map properties in the class as belonging to another table. The only thing to be aware of here is that you are specifying the column names in the join table for your properties manually.

Now to define the join table as optional, you again need to use the SetAttribute method to output the "optional" attribute since there's no inbuilt way to specify that in the JoinPart. Below is the full mapping:

WithTable("Addresses", join =>

                           {

                               join.Map(prop => prop.StreetAddress1, "StreetAddress1");

                            join.Map(prop => prop.StreetAddress2, "StreetAddress2");

                            join.Map(prop => prop.City, "City");

                            join.Map(prop => prop.State, "State");

                            join.Map(prop => prop.ZipCode, "ZipCode");

                               join.WithKeyColumn("PersonId");

                            join.SetAttribute("optional", "true");

                           });

Posted on Thursday, May 14, 2009 8:00 PM | Filed Under [ NHibernate FluentNHibernate ]


Comments

Gravatar
# This is great Ritesh, keep them coming...
Posted by Srdjan
on 5/15/2009 2:17 AM
This is great Ritesh, keep them coming...
Gravatar
# re: FluentNHibernate Mappings: Join
Posted by Uggs outlet
on 11/7/2011 2:30 AM
nice post!
Gravatar
# re: FluentNHibernate Mappings: Join
Posted by mulberry outlet
on 3/7/2012 5:37 AM
Right away Mulberry Bags is wanting to bring back a great deal larger when using multicolor active carriers.
Gravatar
# jordan spizike
Posted by jordan spizike
on 6/21/2012 3:01 AM
full Ritter deal is activities like air jordan 11 retro concords one jordan spizike block concords 11 contrivance to another predominately derived for giddy chance jordan 7 hare or not smart jordan 7 cardinal concord 11 parts.
Gravatar
# re: FluentNHibernate Mappings: Join
on 8/1/2012 7:06 AM
I am pleased that I observed this site, precisely the right information that I was looking for.
Gravatar
# re: FluentNHibernate Mappings: Join
Posted by argan oil
on 10/4/2012 12:44 PM
I am going to join really. I am a regular visitor of this site.
Gravatar
# re: FluentNHibernate Mappings: Join
on 11/6/2012 1:57 AM
michael kors online
Gravatar
# re: FluentNHibernate Mappings: Join
on 11/13/2012 3:48 AM
what is michael kors thanksgiving dayI can't feel of any females that I have ever well-known that have not liked buying for new handbags. I've liked several of time performing nothing but bag looking with many of my affiliates or close relatives. Every encounter was various mainly because each personal individual prefers finished up different. Some needed michael kors outlet handbagsStore with mobile phone and make-up spaces, the place others just want it to get a individual pocket for reduce enhance and breathing mint candies.
No issue what type of handbags each personal particular person got, they all had one thing in extensive. They each and every preferred name design and in any case costly value as possible. Every one of us understand that getting something available for purchase is like effective a small sweepstakes, but to search for out a name product bag like Trainer as an example, reduced is like a piece of paradise in the world. I've individually assaulted my spouse with cuddles and smooches when acquiring michael kors satchel onlineStore at great deals.
Much more than 50 years back Trainer started out its to begin with outlet. They were then partner and kids possessed and had six or 7 individuals handling a number of suppliers. Now you'll discover through 300 Trainer shops with the U.S on your own and you will discover choices to start more shops worldwide with the arriving years. Ny town is exactly where the key head office is located and is a public company. Coach(COH), has workplaces in twenty countries together with Asia. Trainer even has outlet sites all through the whole Usa.
Gravatar
# re: FluentNHibernate Mappings: Join
on 12/5/2012 11:33 AM
I had got a desire to make my organization, but I didn't earn enough of cash to do this. Thank goodness my close colleague advised to take the business loans. So I used the short term loan and realized my desire.
Gravatar
# re: FluentNHibernate Mappings: Join
Posted by replica watches
on 1/5/2013 12:40 AM
Females began putting on replica watches, and design grew to become a element which experienced for being incorporated. All along, watchmakers attempted to produce wrist replica watches uk technologically superior, Swiss watches as properly as the outcome was the innovation of chronographs. These wrist Rolex replica watches might be trusted to display precise time irrespective belonging to the surroundings they had been employed in, and their reliability grew to become legendary.
Gravatar
# discount north face
on 1/15/2013 11:52 PM
Winter or cold weather mountaineering hiking and other activities, the first concern is to own warm, light and warm coat is naturally a good choice, as the cheap north face warm jacket. Excellent detail, waist pockets built strengthen appropriate internal adjustment drawstring and back piece of fabric, in order climbers bad limit the environmental considerations, while discount north face jackets made a humane adjustment, including reflectors the setting is so well-designed, both waterproof pouch discount north face
Gravatar
# re: FluentNHibernate Mappings: Join
Posted by Wizardy
on 2/21/2013 1:16 AM
Our shop is one of the replica watches leading retailer selling refined rolex replica watches online. Years of experience have made swiss replica watches UK us establish long term relationship with our honored customers with high quality rolex replica at low price. Top quality rolex replica watches in our luxury replica watches shop look almost the same as the original ones. They are indistinguishable at the first sight unless you are a watch connoisseur. Therefore, replica watches uk
Gravatar
# re: FluentNHibernate Mappings: Join
on 4/10/2013 12:05 AM
I will be pleased i witnessed this website, the right details i was ready for. My spouse and i guarantee you when time permits, I'll be back again for further involving my own blog jumping below.

Gravatar
# re: FluentNHibernate Mappings: Join
Posted by Joseph
on 4/25/2013 4:11 AM
You actually make it appear so easy with your presentation but I find this matter to be actually something which I think I would never understand. It seems too recondite and extremely broad for me.
essay rewriting || Do assignment for money || free papers online


Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 4 and 2 and type the answer here: