开发者

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

开发者 https://www.devze.com 2023-01-06 23:52 出处:网络
Well, the question kinda nails it down. I\'m currently doing something like this: using (var session = _sessionFactory.OpenSession())

Well, the question kinda nails it down. I'm currently doing something like this:

using (var session = _sessionFactory.OpenSession())
{
     using (var transaction = ses开发者_如何学编程sion.BeginTransaction())
     {
         Car newCar = new Car();
         newCar.name = "Jeep";

         session.Save(newCar);
         transaction.Commit();    
     }
}


return newCar.Id;

After you've committed your transaction of course.

0

精彩评论

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