views:

56

answers:

1

I'm using FluentNHibernate but NHibernate XML will do.

Say I have this model

public User
{
    public User()
    {
        ProfilePicture = new Picture();
    }
    public Guid Id { get; private set; }
    public Picture ProfilePicture { get; set; }
}

public Picture
{
    int width;
    int height;
}

How do I tell NHibernate how to store and retrive the ProfilePicture?

I know in Fluent its like

Map(x => x.ProfilePicture);

but that doesnt work.

+2  A: 

If User and ProfilePicture come from two different tables then you should use References:

References(x => x.ProfilePicture);

If you need to specify the column name it's (e.g.)

References(x => x.ProfilePicture, "ProfilePictureId");

There are several other examples for different use cases in the documentation.

If ProfilePicture is stored in the User table then you would map it as a Component:

Component(x => x.ProfilePicture, c => 
    { 
        c.Map(x => x.width);
        c.Map(x => x.height);
    });
Jamie Ide
I'll be using component. How do I know the naming convention?
Daniel A. White
Fluent NHibernate has a default naming convention or you can specify your own. Personally, I prefer to map out all the properties, etc. rather than use conventions. Here's the doc. on conventions: http://wiki.fluentnhibernate.org/show/StandardMappingConventions
Jamie Ide