查询抛出异常

时间:2017-06-04 06:16:42

标签: c# queryover

我在条件上尝试了这个查询:

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

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

它给我这个例外:

  

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

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

1 个答案:

答案 0 :(得分:2)

您是否尝试使用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);
相关问题