Left outer join issues - FluentMapping for 3.1 and Nhibernate 5.3,

93 views
Skip to first unread message

Venkata Krishna Reddy Sangu

unread,
Dec 14, 2020, 12:38:12 PM12/14/20
to nhusers
Hi Team,
 I have a mapping like below. And Job has 'Department' as property.
 References(x => x.Job)
        .Column(tableMeta.Job_id)
        .Not.LazyLoad().Inverse()
        .Cascade.None();

Query as:
empIds  - input integer ids 
var jobs = _session.Query<TAggregate>()  .Where(e => empIds.Contains(e.EmployeeID))
        .ToList());
var depts = jobs.Departments.
here departments coming as null. Because there is no eagar loading happenings.

How my mappings should be in order to generate left outer join for other entities we used in the property.


Venkata Krishna Reddy Sangu

unread,
Dec 16, 2020, 4:08:56 AM12/16/20
to nhusers
Team, Any idea on this issue?
Default left outer join is not getting created for Hasmany() mapping. Previous version prior to NH 5.3 is working fine.

Oskar Berggren

unread,
Dec 16, 2020, 5:27:50 AM12/16/20
to nhusers
Where is the HasMany() mapping?

Also, you have put Inverse on the References() mapping. I don't think I've ever tried that, I've only ever put Inverse() on the HasMany-side.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhusers+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhusers/b0f49396-d6a3-406d-98de-404e0eeeea79n%40googlegroups.com.

Oskar Berggren

unread,
Dec 16, 2020, 5:30:02 AM12/16/20
to nhusers
Your query example seems seems odd too. The variable `jobs` should be typed as IList<TAggregate> but then you try to access `jobs.Departments` - but `Departments` is hardly defined by the IList<T> interface, so what is really going on?

Venkata Krishna Reddy Sangu

unread,
Dec 17, 2020, 7:24:56 AM12/17/20
to nhu...@googlegroups.com

We upgraded on to NHibernate 5.3.5 from 3 and Fluent NHibernate to 3.1

 

  public class ReasonDataAccessorAssignment

  {

    public virtual int Id { get; protected internal set; }

    public virtual Reason Reason{ get; protected internal set; }

 }

 

public class Reason

  {

    public virtual int ID { get; protected internal set; }

    public virtual IList<ReasonDataAccessorAssignment> ReasonDataAccessorAssignments { get; protected internal set; }

  }

 

Class map:

 

public class ReasonMap : ClassMap<Reason>

  {

    public ReasonMap()

    {

      var tableMeta = "Reason";

      this.Table(tableMeta);

 

      Id(x => x.ID).Column("Reason_id").GeneratedBy.Identity();

 

      HasMany(x => x.ReasonDataAccessorAssignments)

        .KeyColumn("Reason_id")

        .Cascade.AllDeleteOrphan()

        .Not.LazyLoad()

        .BatchSize(100);

    }

}

 

 

Repository call:

 

Var reasons = (from s in _session.Query<Reason>()

              where s.ReasonDataAccessorAssignments != null

              select s).ToList();

 

This query is NOT generating ReasonDataAccessorAssignment table as LEFT OUTER JOIN with latest version

Previous version NHibernate 3 is generating LEFT OUTER JOIN with above query




--

Regards

 

Venkata Krishna Reddy Sangu 

+91 9666121219

BlueYonder

Venkata Krishna Reddy Sangu

unread,
Dec 17, 2020, 7:25:01 AM12/17/20
to nhu...@googlegroups.com

We upgraded on to NHibernate 5.3.5 from 3

 

  public class ReasonDataAccessorAssignment

  {

    public virtual int Id { get; protected internal set; }

    public virtual Reason Reason{ get; protected internal set; }

 }

 

public class Reason

  {

    public virtual int ID { get; protected internal set; }

    public virtual IList<ReasonDataAccessorAssignment> ReasonDataAccessorAssignments { get; protected internal set; }

  }

 

Class map:

 

public class ReasonMap : ClassMap<Reason>

  {

    public ReasonMap()

    {

      var tableMeta = "Reason";

      this.Table(tableMeta);

 

      Id(x => x.ID).Column("Reason_id").GeneratedBy.Identity();

 

      HasMany(x => x.ReasonDataAccessorAssignments)

        .KeyColumn("Reason_id")

        .Cascade.AllDeleteOrphan()

        .Not.LazyLoad()

        .BatchSize(100);

    }

}

 

 

Repository call:

 

Var reasons = (from s in _session.Query<Reason>()

              where s.ReasonDataAccessorAssignments != null

              select s).ToList();

 

This query is NOT generating ReasonDataAccessorAssignment table as LEFT OUTER JOIN with latest version

Previous version NHibernate 3 is generating LEFT OUTER JOIN with above query

On Wed, Dec 16, 2020 at 3:59 PM Oskar Berggren <oskar.b...@gmail.com> wrote:

Venkata Krishna Reddy Sangu

unread,
Dec 17, 2020, 2:33:42 PM12/17/20
to nhusers
Hi Oskar,
Here the entire code with all the claases I am referring to.

We upgraded on to NHibernate 5.3.5 from 3

 

  public class ReasonDataAccessorAssignment

  {

    public virtual int Id { get; protected internal set; }

    public virtual Reason Reason{ get; protected internal set; }

 }

 

public class Reason

  {

    public virtual int ID { get; protected internal set; }

    public virtual IList<ReasonDataAccessorAssignment> ReasonDataAccessorAssignments { get; protected internal set; }

  }

 

Class map:

 

public class ReasonMap : ClassMap<Reason>

  {

    public ReasonMap()

    {

      var tableMeta = "Reason";

      this.Table(tableMeta);

 

      Id(x => x.ID).Column("Reason_id").GeneratedBy.Identity();

 

      HasMany(x => x.ReasonDataAccessorAssignments)

        .KeyColumn("Reason_id")

        .Cascade.AllDeleteOrphan()

        .Not.LazyLoad()

        .BatchSize(100);

    }

}

 

 

Repository call:

 

Var reasons = (from s in _session.Query<Reason>()

              where s.ReasonDataAccessorAssignments != null

              select s).ToList();

 

This query is NOT generating ReasonDataAccessorAssignment table as LEFT OUTER JOIN with latest version

Previous version NHibernate 3 is generating LEFT OUTER JOIN with above query 



Reply all
Reply to author
Forward
0 new messages