UpTheCreek
UpTheCreek

Reputation: 32391

Fluent NHibernate: mapping one-to-one

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://nhibernate.info/blog/2009/04/18/nhibernate-mapping-lt-one-to-one-gt.html

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

Upvotes: 1

Views: 918

Answers (2)

UpTheCreek
UpTheCreek

Reputation: 32391

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

HasOne(x => x.Cover);

Missed it somehow before :/

Upvotes: 2

dove
dove

Reputation: 20674

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

        }

Upvotes: 0

Related Questions