O'Reilly logo

Learning NHibernate 4 by Suhas Chatekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving entities

As with previous chapter, we will begin by going through a piece of code we had used in Chapter 3, Let's Tell NHibernate About Our Database. If you can remember, we had used the following code to save an instance of the Employee class in the database:

object id = 0;
using (var transaction = Session.BeginTransaction())
{
  id = Session.Save(new Employee
  {
    EmployeeNumber = "5987123",
    Firstname = "Hillary",
    Lastname = "Gamble",
    EmailAddress = "hillary.gamble@corporate.com",
    DateOfBirth = new DateTime(1980, 4, 23),
    DateOfJoining = new DateTime(2010, 7, 12),
    IsAdmin = true,
    Password = "Password"
  });
  transaction.Commit();
}

We started with call to Session.BeginTransaction which signaled NHibernate to begin a fresh transaction for us. We ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required