我正在尝试为两个不同的设备进行成对测量,并在相同的时间戳上加入。在SQL中,这可以按预期工作:
select
leftItem.Timestamp, leftItem.Value, rightItem.Value
from
DataTable leftItem
inner join DataTable rightItem
on leftItem.Timestamp = rightItem.Timestamp
where
leftItem.Device = 1 and rightItem.Device = 2
但如果我尝试将其转换为HQL:
select
left, right
from
DataTable as left
inner join DataTable as right
on left.Timestamp = right.Timestamp
where
left.Device = 1 and right.Device = 2
我得到NHibernate.Hql.Ast.ANTLR.SemanticException:
Path expected for join!
如何指定同一个表的“路径”?
答案 0 :(得分:6)
在HQL中,只能对实体之间的关联进行连接。如果你想要连接其他东西,唯一的可能是在where子句中进行连接:
select left, right
from
DataTable as left, DataTable as right
where
left.Timestamp = right.Timestamp
and left.Device = 1
and right.Device = 2