I wonder what is the difference between Save() and SaveOrUpdate() methods in nHibernate, and what I right know is that the main difference is that:
Save()
- return id of a saved entity
- simply saves an entity (without update?)
SaveOrUpdate()
doesn't return an id of a saved entity
Invokes Save() (if entity doesn't exist in db), or invokes Update() (if entity exists)
But my question is that, is Save() in nHibernate is similar to Save() in java Hibernate? Because if I want to write simple function, which will save entity and return me only the id of an already saved entity. I should write function like that:
public int ReturnMeAnIdOfSavedEntity(IEntity ent)
{
_session.SaveOrUpdate(ent);
return ent.Id;
}
or I can write function like that:
public int ReturnMeAnIdOfSavedEntity(IEntity ent)
{
return (int)_session.Save(ent);
}
I also found questions and blogs about Save() but in Hibernate, not in NHibernate, so I'm not 100% right if the function play similar.
Related question/blogs
Thanks for answers!