Fluent Nhibernate left join

五迷三道 提交于 2019-12-03 15:30:23

问题


I want to map a class that result in a left outer join and not in an innner join.

My composite user entity is made by one table ("aspnet_users") and an some optional properties in a second table (like FullName in "users").

  public class UserMap : ClassMap<User> {
    public UserMap() {
        Table("aspnet_Users");
        Id(x => x.Id, "UserId").GeneratedBy.Guid();
        Map(x => x.UserName, "UserName");
        Map(x => x.LoweredUserName, "LoweredUserName");

       Join("Users",mm=>
                        {
                            mm.Map(xx => xx.FullName);

                        });
    }
}

this mapping result in an inner join select so no result come out is second table as no data. I'd like to generate an left join.

Is this possible only at query level?


回答1:


Try the Optional() method.

Join("Users", m =>
{
  m.Optional();
  m.Map(x => x.FullName);
});



回答2:


Only this did work for me (NH 3.3):

Join("OuterJoinTable",
                m =>
                {
                    m.Fetch.Join().Optional();
                    m.KeyColumn("ForeignKeyColumn");

                    m.Map(t => t.Field, "FieldName");
                });


来源:https://stackoverflow.com/questions/1354177/fluent-nhibernate-left-join

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!