NHibernate + Free Long Run Time

I am new to NHibernate. When performing the below test it took 11.2 seconds (debug mode), I see this is a great launch time in all my tests (basically, creating the first session takes a lot of time)

setup = Windows 2003 SP2 / Oracle10gR2 latest processor /ODP.net 2.111.7.20/FNH 1.0.0.636/NHibernate 2.1.2.4000/NUnit 2.5.2.9222/VS2008 SP1

using System;
using System.Collections;
using System.Data;
using System.Globalization;
using System.IO;
using System.Text;
using System.Data;
using NUnit.Framework;
using System.Collections.Generic;
using System.Data.Common;
using NHibernate;
using log4net.Config;
using System.Configuration;
using FluentNHibernate;

[Test()]
        public void GetEmailById()
        {

            Email result;

            using (EmailRepository repository = new EmailRepository())
            {
                results = repository.GetById(1111);
            }

            Assert.IsTrue(results != null);
        }

//In my Repository

   public T GetById(object id)
        {
            using (var session = sessionFactory.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                try
                {
                    T returnVal = session.Get<T>(id);
                    transaction.Commit();
                    return returnVal;
                }
                catch (HibernateException ex)
                {
                    // Logging here
                    transaction.Rollback();
                    return null;
                }
            }
        }

The request time is very short. The resulting object is really small. Subsequent requests are in order.

It seems to be starting the first session.

Has anyone else seen something like this?

edit1:

public RepositoryBase()
{ 
  config = Fluently.Configure()
    .Database(OracleClientConfiguration.Oracle10 
    .ConnectionString(c => c.FromConnectionStringWithKey("DBCONSTRING"))
    .Driver<NHibernate.Driver.OracleDataClientDriver>().ShowSql()) 
    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MYASSEM>()) 
    .BuildConfiguration(); 

  sessionFactory = config.BuildSessionFactory(); 
}
+3
source share
3 answers

this. , , .

+4

SessionFactory .

SessionFactory ( ). .

, / .

+3

log4net DEBUG? NHibernate alsolog , -. DEBUG . NHibernate, :

   <log4net>
    <root>
      <appender-ref ref="SqlServerAppender" />
      <level value="DEBUG" />
    </root>
    <logger name="NHibernate">
      <level value="ERROR"/>
    </logger>
   </log4net>
+1

Source: https://habr.com/ru/post/1741103/


All Articles