11

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.

Community
  • 1
  • 1
MylesRip
  • 1,212
  • 17
  • 29

1 Answers1

7

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
cremor
  • 6,669
  • 1
  • 29
  • 72
  • Thanks for the reply, cremor. In my situation, I use CreateCriteria to retrieve a list of objects at the aggregate root level. The aggregate root is 2 levels above the "ItemAsmtDetailDh" class mentioned in my question. I then delete the parent of ItemAsmtDetailDh (1 level up). NH is retrieving the rest of the aggregate from that point downward in order to delete it. I would consider this a case of retrieval by navigation of associations. – MylesRip Jun 16 '11 at 15:03