C# 连接所需的HQL路径(连接同一个表时)
我试图得到两个不同设备的成对测量值,在相同的时间戳上连接。在SQL中,这可以按预期工作:C# 连接所需的HQL路径(连接同一个表时),c#,sql,nhibernate,hql,inner-join,C#,Sql,Nhibernate,Hql,Inner Join,我试图得到两个不同设备的成对测量值,在相同的时间戳上连接。在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 rightIt
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!
预期加入的路径!
如何为同一个表指定“路径”?在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
当您遇到这个错误时,您在HQL中尝试了什么?@Stefan:实际上,这是同一个查询。(好的,我会编辑它来澄清)谢谢!在服务器上对其进行评估的方式是否有差异(性能方面)?还是结果上的差异?毕竟,我也可以求助于普通SQL。打开SQL日志以查看生成的SQL,并比较两个执行计划。这取决于数据库。