开发者

Using a join in Hibernate HQL update query

开发者 https://www.devze.com 2022-12-09 07:20 出处:网络
string query = \"update User u set u.PointsTotal = 1 join u.Rounds r where r.RoundId = :round and (r.Row1 & :val) > 0\";
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

精彩评论

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