Note that there are some explanatory texts on larger screens.

plurals
  1. PONHibernate ReferencesAny Fetching?
    text
    copied!<p>I have a class with a ReferencesAny map. For certain queries, I end up with an N+1 situation on that Any Map. Is there a way to use Fetch for an any map?</p> <p>Here's what my linq query looks like (this works, but poor performance due to N+1):</p> <pre><code>return Session.Query&lt;Path&gt;().Where(p =&gt; {condition}).ToArray().Select(p =&gt; p.ContentsObject); </code></pre> <p>When I add a fetch into the mix:</p> <pre><code>return Session.Query&lt;Path&gt;().Where(p =&gt; {condition}).Fetch(p =&gt; p.ContentsObject).Select(p =&gt; p.ContentsObject); </code></pre> <p>The query blows up saying there is an invalid join.</p> <p>Exception:</p> <p>Invalid join: p.Page [.Fetch[wp.cms.DomainModel.Entity.Structure.PagePathMemento,wp.cms.DomainModel.Entity.Base.ILocatablePage](.Where[wp.cms.DomainModel.Entity.Structure.PagePathMemento](NHibernate.Linq.NhQueryable`1[wp.cms.DomainModel.Entity.Structure.PagePathMemento], Quote((p, ) => (.Any[wp.cms.DomainModel.Entity.Users.UserSite](p.Site.Users, (u, ) => (Guid.op_Equality(u.User.Id, p1)), ))), ), Quote((p, ) => (p.Page)), )] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.</p> <p>Exception Details: NHibernate.Hql.Ast.ANTLR.InvalidPathException: Invalid join: p.Page [.Fetch[wp.cms.DomainModel.Entity.Structure.PagePathMemento,wp.cms.DomainModel.Entity.Base.ILocatablePage](.Where[wp.cms.DomainModel.Entity.Structure.PagePathMemento](NHibernate.Linq.NhQueryable`1[wp.cms.DomainModel.Entity.Structure.PagePathMemento], Quote((p, ) => (.Any[wp.cms.DomainModel.Entity.Users.UserSite](p.Site.Users, (u, ) => (Guid.op_Equality(u.User.Id, p1)), ))), ), Quote((p, ) => (p.Page)), )]</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload