开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜