views:

258

answers:

2

NHibernate seems to support a special case of one to one mapping (That doesn't require a 1-m mapping on each side of the relationship).

See this article by Ayende:

http://nhforge.org/blogs/nhibernate/archive/2009/04/19/nhibernate-mapping-lt-one-to-one-gt.aspx

I have no idea how to specify this in Fluent NHibernate though - is this possible?

A: 

One scenario is with subclasses. You can specific a table per hierarchy or per class.

You would need to override for the per hierarchy something like below:

 public class UserMap : IAutoMappingOverride<User>
    {
        public void Override(AutoMapping<User> mapping)
        {
            mapping.DiscriminateSubClassesOnColumn<int>("UserType");

        }
    }

        public void Override(AutoMapping<Person> mapping)
        {
            mapping.Table("Persons");

            DiscriminatorValue((int)UserTypes.Person);

        }
dove
Thanks. I was hoping there would be a less complicated way of doing it :) I guess this would mean that there would have to be an inheritance relationship between the two objects though? I don't really want to do that.
UpTheCreek
+2  A: 

Ah, just found from a helpful person in the Fluent group that I can use

HasOne(x => x.Cover);

Missed it somehow before :/

UpTheCreek

related questions