Nhibernate:没有持久性:System.Collections.Generic.List

时间:2013-01-18 16:22:55

标签: nhibernate queryover

在执行下面的查询时,为什么我可能会收到“No 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 个答案:

答案 0 :(得分:1)

问题很可能在于您如何创建subsections “子查询”。请尝试检查此答案:https://stackoverflow.com/a/14080092/1679310

注意:缺少您的映射和类的定义,因此请将其作为基于您的代码段的“操作方法”。您应该创建分离的查询:

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然后将subselect注入你的主查询)。

...或提供有关映射的更多详细信息..