开发者

ASP.NET with NHibernate - How can I get the ID of an entity just inserted on postback

开发者 https://www.devze.com 2023-01-08 08:37 出处:网络
As per title. Using native ID\'s The only thing I can think to do is to call GetByExample(entityJustInserted)开发者_开发技巧 and pick the one with the highest ID. Not great...anyone got a better way?

As per title. Using native ID's

The only thing I can think to do is to call GetByExample(entityJustInserted)开发者_开发技巧 and pick the one with the highest ID. Not great...anyone got a better way?

Thanks.


You can get it directly off of the entity you just inserted:

For example:

entityRepository.Save(entity);
return entity.Id;

NHibernate will automatically populate the property with the generated id.

0

精彩评论

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