Is there a way to return the primary key of an inserted record in NHibernate?

Well, the question, however that may be. I am currently doing something like this:

using (var session = _sessionFactory.OpenSession()) { using (var transaction = session.BeginTransaction()) { Car newCar = new Car(); newCar.name = "Jeep"; session.Save(newCar); transaction.Commit(); } } 
+4
source share
1 answer
 return newCar.Id; 

After you have completed the transaction, of course.

+7
source

Source: https://habr.com/ru/post/1315702/


All Articles