Hmm, one solved, one to go!
Returning identity was (as I thought) simple!
Code:
ITransaction transaction = CurrentSession.BeginTransaction();
Category cat = new Category();
cat.Name = "test2";
CurrentSession.Save(cat);
transaction.Commit();
int id = cat.Id;
NHibernate adds the id automaticly for me to my class! :)
So, what about updating the parentid? How do I solve that?
I tried to add a property field to the map file like
Code:
<class name="Swh.Entities.Category, Swh.Entities" table="Categories">
<id name="Id" column="CategoryId" type="int" unsaved-value="0">
<generator class="identity" />
</id>
<many-to-one name="Parent" column="ParentId" />
<property name="ParentId" column="ParentId" type="int"/>
<property name="Name" column="CategoryName" type="String"/>
</class>
But then I just get an error saying I got duplicate columns! :(
I also tried this:
Code:
ITransaction transaction = CurrentSession.BeginTransaction();
Category cat = new Category();
cat.Id = 12345;
cat.Name = "test";
cat.Parent.Id = 54321;
CurrentSession.SaveOrUpdate(cat);
transaction.Commit();
But then I just got "Object reference not set to an instance of an object" on the cat.Parent.Id line.