I'm quite new to nHibernate, so this'll probably be a pretty stupid question. But anyway, saving an object works fine, updating it doesn't work.
This is what I'm doing:
using (ISession session = _sessionFactory.OpenSession())
{
session.SaveOrUpdate(schemaChange);
schemaChange.ScriptName = "New one";
session.SaveOrUpdate(schemaChange);
}
The first SaveOrUpdate inserts a schemaChange in the database. The second one should update the same object, but nHibernate doesn't do that.
In the output I get:
DEBUG - persistent instance of: DotNetMigrations.Core.Domain.SchemaChange
DEBUG - ignoring persistent instance
DEBUG - object already associated with session: [DotNetMigrations.Core.Domain.SchemaChange#129]
UPDATE
Well, as it was so simple (and a stupid question), I found it myself:
session.SaveOrUpdate(schemaChange);
schemaChange.ScriptName = "New one";
session.Flush();
Makes sence. nHibernate is really superior to any orm tool I've worked with.
What I can't seem to figure out is why there's a SaveOrUpdate method... If you're updating, then isn't the object automatically already associated with the session? (because you got it out of the db in the first way. Unless off course you sent it to for example a Flex RIA and it came back)
So, how do you know if the object is already associated, to either do a SaveOrUpdate() or just a Flush()?