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.
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
精彩评论