NHibernate: Can I access a generated primary key after saving a model?
Posted
by littlecharva
on Stack Overflow
See other posts from Stack Overflow
or by littlecharva
Published on 2010-04-22T10:49:42Z
Indexed on
2010/04/22
10:53 UTC
Read the original article
Hit count: 227
nhibernate
Howdy,
So I've got a simple table with an ID field that's incrementally generated on INSERT.
I've set the mapping up in NHibernate to reflect this:
<id name="ID">
<generator class="identity" />
</id>
And it all works fine.
Trouble is, I need to get the generated ID after I've saved a new model to use elsewhere:
var model = new MyModel();
session.SaveOrUpdate(model);
But at this stage model.ID == null, not the ID.
Any ideas?
Anthony
© Stack Overflow or respective owner