views:

143

answers:

2

does nhibernate parse xml files everytime someone makes a request or just once when the application starts ?

well here is what i m doing :

public class SessionManager
{
    private readonly ISessionFactory _sessionFactory;

    public SessionManager()
    {
        _sessionFactory = GetSessionFactory();
    }

    public ISession GetSession()
    {
        return _sessionFactory.OpenSession();
    }

    private static ISessionFactory GetSessionFactory()
    {
        return Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2005
                          .ConnectionString(c =>
                                            c.Is(
                                                @"Data Source=Pc-De-Yassir;Initial Catalog=MyDatabase;User Id=sa;Password=password;Integrated Security=True")
                          ))
            .Mappings(m =>
                      m.AutoMappings.Add
                          (
                          AutoPersistenceModel.MapEntitiesFromAssemblyOf<Model.Category>()
                          ))
            .BuildSessionFactory();
    }
}

and here is how i get data from the database

public IList<Category> GetCategories()
    {
var session = new SessionManager().GetSession();
        return session.CreateCriteria(typeof(Category))
            .List<Category>();}

So my question is will nhibernate configure itself the first time this method run or each time a request is made ?

+3  A: 

Once each time you instantiate an ISessionFactory off the top of my head...

David M
.. which should happen just once when the app starts.
Matt Hinze
Yes. But obviously depends how you've written it...
David M
+2  A: 

It does it only once. If you would like to improve the performance of the application, use ngen.exe tool. nHibernate is usually slow for the first time, because of the amount of code that need to be compiled when the application starts for the first time.

I had similiar probles with performance at application startup, and ngen.exe solved my problems.

Adam