在Hibernate HQL更新查询中使用连接

时间:2009-10-27 09:24:49

标签: nhibernate join hql

string query = "update User u set u.PointsTotal = 1 join u.Rounds r where r.RoundId = :round and (r.Row1 & :val) > 0";

NHibernateSession.CreateQuery(query)
    .SetByte("val", (byte)val)
    .SetInt32("round", roundId)
    .ExecuteUpdate();

请给我“字典中没有给定的密钥。”

是的,关系按预期工作,可以选择......

1 个答案:

答案 0 :(得分:5)

好的解决了这个,好像你要做一个子查询...

string query = "update User u set u.PointsTotal = 1 where u.Id in (select u2.Id from User u2 join u2.Rounds r where r.RoundId = :round and (r.Row1 & :val) > 0)";

NHibernateSession.CreateQuery(query)
    .SetByte("val", (byte)val)
    .SetInt32("round", roundId)
    .ExecuteUpdate();