且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Fluent NHibernate:如何在映射类中映射“外键"列

更新时间:2021-12-31 09:02:20

给你:

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

话虽如此,使用 Automapper 配置更容易.

That being said, it's easier using the Automapper configuration.