2012/5/15 Brian Berns <[email protected]>:
> I have code that looks like this:
>
> using (var session = this.sessionCreator.OpenSession())
> using (var transaction = session.BeginTransaction())
> {
>     session.SaveOrUpdate(anObject);
>     session.CreateSQLQuery(sql)
>         .ExecuteUpdate();
>     transaction.Commit();
> }
>
> Surprisingly, the SQL query executes before anObject is saved. Apparently,

It is not surprising. SaveOrUpdate() does NOT imply "execute sql now".


> the ExecuteUpdatecommand does not participate in the current transaction. Is
> there any way to get the update to enlist in the transaction?

I don't see how you can reach that conclusion based on the information
given. If you remove the call to Commit(), are the changes still
present in the database? I think it's just a matter of calling Flush()
on the session before ExecuteUpdate() if you need to guarantee that
any dirty state has been flushed to the DB before you SQL query. I
think NH can't do that automatically in this case.

/Oskar

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to