views:

41

answers:

1

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.

+7  A: 

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.

DanP
doh! i just found that out myself too, thanks.
empo
Also, `Save` returns the new id too (in case it's private or non-mapped)
Diego Mijelshon