【问题标题】:Cannot use subqueries on a criteria without a projection不能在没有投影的条件上使用子查询
【发布时间】:2021-06-25 16:08:06
【问题描述】:

NHibernate.QueryException: '不能在没有投影的条件上使用子查询。'

基本错误:

            WorkEntity workEntity = null;
            QueryOver<WorkEntity, WorkEntity> result = QueryOver.Of(() => workEntity);

            Conjunction conjunction = Restrictions.Conjunction();
            QueryOver<WorkDetailEntity, WorkDetailEntity> workDetailEntity = QueryOver.Of<WorkDetailEntity>();

            foreach (ISearchSpecsFilter item in searchFilter.SpecsFilter) {

                if (item.MinValue + item.MinValue != 0) {

                    conjunction.Add(Restrictions.Where<WorkDetailEntity>(w => w.Value >= item.MinValue && w.Value <= item.MaxValue));

                }

            }

            result
                .WithSubquery
                .WhereExists(workDetailEntity.Where(conjunction).And(w => w.Work.WorkId == workEntity.WorkId));

【问题讨论】:

    标签: c# visual-studio nhibernate fluent-nhibernate


    【解决方案1】:

    例子:

    错误:

    result
      .WithSubquery
      .WhereExists(workDetailEntity.Where(conjunction).And(w => w.Work.WorkId == workEntity.WorkId));
    

    正确:

    result
      .WithSubquery
      .WhereExists(workDetailEntity.Where(conjunction).And(w => w.Work.WorkId == workEntity.WorkId).Select(s => s.Work.WorkId));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      相关资源
      最近更新 更多