O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

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

Creating a session factory

To create sessions through which we can access the database, we need a session factory. Every session object that we ever need has to be created with the aid of such a session factory. Once again, we can use the classes provided by Fluent NHibernate to make things simple. We use the Fluently helper class to define, in a fluent way, the necessary information NHibernate needs to be able to create a session factory for us.

Specifically, we have to define what database product and which version of it we are going to use. We also have to define where Fluent NHibernate can find all the mapping files we have written. This leads us to the following code:

private ISessionFactory CreateSessionFactory() { return Fluently.Configure().Database(MsSqlConfiguration.MsSql2008.ConnectionString(connString)).Mappings(m ...

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