开发者

Using a join in Hibernate HQL update query

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

NHibernateSession.C开发者_开发技巧reateQuery(query)
    .SetByte("val", (byte)val)
    .SetInt32("round", roundId)
    .ExecuteUpdate();

Just gives me "The given key was not present in the dictionary."

And yes, the relations works as expected, can do selects....


Ok solved this one, seems like you have to do a subquery...

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜