我有一個帶有ReferencesAny地圖的類。對於某些查詢,我在任何地圖上都會出現N + 1的情況。有沒有辦法使用Fetch獲取任何地圖?NHibernate ReferencesAny Fetching?
這裏是我的LINQ查詢是什麼樣子(這工作,但性能差,由於N + 1):
return Session.Query<Path>().Where(p => {condition}).ToArray().Select(p => p.ContentsObject);
當我添加一個取到組合:
return Session.Query<Path>().Where(p => {condition}).Fetch(p => p.ContentsObject).Select(p => p.ContentsObject);
查詢打起來說有一個無效的加入。
例外:
無效加入:p.Page [.Fetch [wp.cms.DomainModel.Entity.Structure.PagePathMemento,wp.cms.DomainModel.Entity.Base.ILocatablePage](其中[可溼性粉劑。 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)),)] 描述:執行當前Web請求期間發生未處理的異常。請查看堆棧跟蹤以獲取有關該錯誤的更多信息以及源代碼的位置。
異常詳細信息:NHibernate.Hql.Ast.ANTLR.InvalidPathException:無效連接:p.Page [.Fetch [wp.cms.DomainModel.Entity.Structure.PagePathMemento,wp.cms.DomainModel.Entity.Base.ILocatablePage ](。)其中[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)),)]
顯示完整的異常+內部異常的消息。 – gdoron 2012-02-08 20:37:14