I’m using Fluent NHibernate in an Asp.net MVC application. I have it set up to start a session and transaction on every request, and commit the transaction at the request end. However, what I want to do is save an object (in this case, a new “Company”) and then redirect to that new Company’s detail page. How do I get the Id of the new company so that I can redirect? If I get the Id after session.Save(company), it is null. This makes sense as it hasn’t yet been committed, however, it still seems there should be a relatively easy way to do this without committing the current transaction and starting a new one.
Share
OK, the problem was elsewhere in my code. You can get the Id immediately after save, even if you haven’t committed the transaction or flushed it.
Thanks everyone for the answers, but unfortunately none of them are entirely correct.