2013-01-18 71 views
1

任何想法,爲什麼我可能會得到「沒有persister:System.Collections.Generic.List」異常時執行下面的查詢?Nhibernate:沒有persister for:System.Collections.Generic.List

 var subs = new List<Subsection>(); 

     var subsections = Session.QueryOver<Subsection>() 
          .WhereRestrictionOn(s => s.Id) 
          .IsInG(subsectionIds) 
          .List<Subsection>(); 

     Location foreignExpertLocation = null; 

     var result = Session.QueryOver<InternationalLawyerExpertise>() 
      .JoinAlias(i => i.ForeignExpertLocation,() => foreignExpertLocation) 
      .JoinAlias(() => foreignExpertLocation.Subsections,() => subs) 
      .AndRestrictionOn(() => subs).IsInG(subsections) 
      .Where(i => i.ForeignExpertLocation == location && i.Status.Id == _confirmed) 
      .Fetch(lawyer => lawyer.PersonOrganisation.Person).Eager 
      .Fetch(lawyer => lawyer.PersonOrganisation.Organisation).Eager 
      .List<InternationalLawyerExpertise>(); 
     return result; 

回答

1

問題最有可能是在路上,你是如何創建subsections「子查詢」。嘗試檢查這個答案:https://stackoverflow.com/a/14080092/1679310

注:沒有缺少你映射和類definiton,所以把這個作爲一個「如何」根據您的片斷。您應該創建分離的查詢:

var subQuery = QueryOver.Of<<Subsection>() 
    .WhereRestrictionOn(s => s.Id) 
    .IsInG(subsectionIds) 
    .Select((s) => s.ID); // ID projection 

,然後使用它:

var result = Session.QueryOver<InternationalLawyerExpertise>() 
    ... 
    .Where(Subqueries.PropertyIn("SubsectionID", subQuery.DetachedCriteria)) 

這樣你就可以直接與一個選擇過濾器內部的選擇(當時的NHibernate將注入的子查詢到你的主查詢)。

...或提供有關映射的更多細節..

+0

我映射到一些表格不正確,但基本上是你的解決方案工作。 –

相關問題