how do we do this mapping but fluently?
<class name="Person" table="People">
<id name="Id">
<generator class="identity"/>
</id>
<property name="Name" />
<join table="Addresses">
<key column="PersonId"/>
<property name="Line1"/>
<property name="Line2"/>
<property name="City"/>
<property name="Country"/>
<property name="ZipCode"/>
</join>
</class>
I know i can use ‘References’ but i don’t need all the columns from the related table. i just need one property.
What Paco said is not right. This can be done in Fluent NHibernate.
I searched the web myself quite a while, couldn’t find anyone talking about this option, so I just played around with FNHibernate a little and finally managed to do it.
This was my scenario :
I have two tables –
These were my entities :
I have a couple of methods in my query that return a list of
FormStructureobjects. I wanted these methods to give me them ordered by theDisplayOrderfield in theFormFieldobject, and wanted theDisplayOrderavailable as a property in myFormStructureobject for other reasons as well.This basically means I needed to join the tables so that I would retrieve all the columns from the FormStructure table along with the
DisplayOrdercolumn from theFormFieldtable, joining them on the matchingFieldIdcolumns.What I did to solve this :
I added a property called DisplayOrder to my
FormStructureobject.I added the
Joinmethod to myFormStructuremapping class so it looked like this.The
Joinmethod will obviously join between the two tables on the column you defined in the KeyColumn method within the Join.This will also remove some of the rows that have null values. In order to avoid this (I ran into this recently) you can add
m.Optional();inside theJoinmethod.I could now retrieve a list of
FormStructureobjects, order them byDisplayOrderand even haveDisplayOrderavailable as a property in theFormStructureobject.This couldn’t have been done before, because it wouldn’t have recognized the
DisplayOrdercolumn in the Order clause I have there.