views:

34

answers:

2

Let's start with this mapping:

<component name="Location">
  ...
  <property name="Settings" type="JsonUserType,...">
    <column name="LocationSettingsType" />
    <column name="LocationSettingsData" />
  </property>
</component>

This maps to

TABLE Primary (
    ...
    LocationSettingsType,
    LocationSettingsData
    ...
)

and

class Location {
    ...
    object Settings { get; set; }
}

Now, I want to extract settings into a separate table (because they are seldom here).
So I get

TABLE Primary (
    ...
    LocationSettingsId,
    ...
)

TABLE Settings (
    Id,
    Type,
    Data
)

Can I keep my C# classes the same?

Update: This is not a many-to-one relationship. As before, each location has zero or one settings, and each settings belong to at most one location.

A: 

I believe the closest thing that exists to this is the <map> mapping element; details are explained in this article.

DanP
Map requires dictionary, and I do not have a dictionary in my C# model, I opted for JsonUserType instead (because I do not need to process settings on the DB side and I want strong typing in C#).
Andrey Shchekin
A: 

If you want a one to many relationship on the Primary and Settings tables, you'll have to set a foreign key constraint first. Then you'll use the bag property in XML to map your tables. You will have an entity for each table.

See also this question on NHibernate/FluentNHibernate Property Bag.

I also recommend you purchase the NHibernate 2 for Beginners book. It helped me alot.

0A0D
No, as before the table split, it should still be a one to one relationship.
Andrey Shchekin