Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch.Join() not working in Fluent NHibernate

I have the following mapping override on one side of the relationship:

public void Override(AutoMapping<ItemAsmtDetailDh> mapping)
{
    mapping.HasMany<WAsmtDetail>(x => x.WAsmtDetails).Inverse().AsBag().Cascade.AllDeleteOrphan().Access.PascalCaseField(Prefix.Underscore).Not.LazyLoad().Fetch.Join();
}

and on the other side of the relationship I have:

public void Override(AutoMapping<WAsmtDetail> mapping)
{
    mapping.References<ItemAsmtDetailDh>(x => x.ItemAsmtDetailDh).Not.Nullable().Not.LazyLoad().Fetch.Join();
}

When I use the ShowSql option I see that it's still issuing separate select statements for the WAsmtDetails giving me the dreaded "n + 1 selects" problem. Why is ".Not.LazyLoad().Fetch.Join()" being ignored?

Note: I'm using Fluent NHibernate version 1.1, not version 2.1, because of a bug in the newer version. (See my answer for this question for bug details.) I'm using NHibernate version 2.1.2.4000.

like image 501
MylesRip Avatar asked Jun 15 '11 17:06

MylesRip


1 Answers

You are most likely loading the data in a way that isn't affected by Fetch.Join() in the mapping (like HQL or Linq). From the NHibernate documentation:

The fetch strategy defined in the mapping document affects:

  • retrieval via Get() or Load()
  • retrieval that happens implicitly when an association is navigated
  • ICriteria queries
  • HQL queries if subselect fetching is used
like image 177
cremor Avatar answered Sep 18 '22 03:09

cremor