how to run update HQL query in nHibernate?

0 votes
asked Jun 15, 2009 by dotnetcoder

I could not find any query.executeUpdate() method in IQuery interface or ISession where i can pass an hql to update a record.

here is the hql:

string hql = "update QAD qa set qa.NFS=:NFS where qa.ID = 1145";
IQuery q = session.CreateQuery(hql).SetString("NFS", "10");

1 Answer

0 votes
answered Jun 15, 2009 by bernhardrusch

In NHibernate we are doing it a little bit different: you get the structure from the database, change the value and then commit the changes. I don't think it is possible to do this more directly...

//Pseudocode
T t = session.Get<T>(id);
t.NFS = 10;
session.SaveOrUpdate(t);
session.Transaction.Commit();
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...