【问题标题】:Query over throws exception查询抛出异常
【发布时间】:2017-06-04 06:16:41
【问题描述】:

我根据条件尝试了这个查询:

Area area = null
var res = session.QueryOver<Area>(() => area);

res.UnderlyingCriteria.Add(Expression.Where<Area>(x => x.shops.where(s => s.Id == 40503) != null));

它抛出了这个异常:

“从范围引用的类型为Area的变量x,但未定义”

有人知道为什么会这样吗?

【问题讨论】:

  • 我在那里写的不是空的。我想返回包含 id 为 40503 的商店的区域(id 是示例)
  • 我已经试过了。它向我抛出了同样的异常,我知道问题出在基本标准中,因为如果我稍微改变一下它就可以工作(但不检查我搜索的内容)

标签: c# queryover


【解决方案1】:

您是否尝试过使用您的 area 别名?

res.UnderlyingCriteria.Add(Expression.Where<Area>(() => area.shops.where(s => s.Id == 40503) != null));

即使这看起来过于复杂。这样会更好:

Area area = null;
Shop shop = null
var res = session.QueryOver<Area>(() => area)
.Left.JoinAlias(() => area.shops, () => shop)
.Where(() => shop.Id == 40503);

【讨论】:

    猜你喜欢
    • 2015-09-02
    • 2020-03-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2011-10-17
    相关资源
    最近更新 更多