I\'m starting to develop with Fluent NHiberate, and I was wondering how I create a defined \'Foreign Key\' relationship in my Mapping class.
Here\'s my class. These
Here you go:
public class Song
{
public virtual int Id { get; private set; }
public virtual Artist Artist { get; set; }
public virtual string Title { get; set; }
public class SongMap : ClassMap<Song>
{
SongMap()
{
Id(c => c.Id);
References(c => c.Artist); // Yes, that's all.
Map(c => c.Title).Not.Nullable().Length(50);
}
}
}
That being said, it's easier using the Automapper configuration.
I have things to work with identifiers via next (tested on my entities, here just renamed things and no run was done, please consider it as patter to try):
References<Artist>(x => x.SongArtistID ).Column("SongArtistID").ForeignKey("ArtistID");