Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent Nhibernate left join

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?

like image 389
Ronnie Avatar asked Aug 30 '09 16:08

Ronnie


1 Answers

Try the Optional() method.

Join("Users", m =>
{
  m.Optional();
  m.Map(x => x.FullName);
});
like image 127
James Gregory Avatar answered Sep 17 '22 13:09

James Gregory