1

任何想法为什么我在执行下面的查询时可能会得到“没有持久性: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;
4

1 回答 1

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 然后将子选择注入您的主查询)。

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

于 2013-01-18T16:34:25.780 回答