Friday 2 March 2007

nHibernate Get or Load?

Session.Get and Session.Load do very similar things, the difference is.

.Get will return null if a record is not found.
.Save will return an exception if a record is not found, and if it can use a proxy, it will return a proxy, so you won't get the exception until you try to actually use the object.

If you are not sure that a record exists then use .Get and check that the object isn't null.