Fluent NHibernate join single column from another table

后端 未结 2 601
清歌不尽
清歌不尽 2021-02-07 18:38

I\'m using Fluent NHibernate and have two tables;

Customer [ID, Name, LanguageID]

Languages [ID, Description]

I have a Customer entity with the following

2条回答
  •  执念已碎
    2021-02-07 19:06

    I haven't used Join before but I think you want the foreign key from Customer in your mapping:

        Table("ScriptActivities");
        Not.LazyLoad();
        Id(c => c.ID).GeneratedBy.Assigned();
        Map(c => c.Name);
        Map(c => c.LanguageID);
        Join("Languages", join =>
        {
            join.KeyColumn("LanguageID");
            join.Map(prop => prop.Language).Column("Description");
        });
    

    Edited to add: The best example I could find on the join mapping is Ayende's blog. From that example, it appears to me that join is expecting the ID of the mapped object to be a foreign key in the joined table. Your schema has the joined table ID as a FK in the mapped object so join won't work. I suggest creating a view combining Customer and Language and mapping that.

提交回复
热议问题