NHibernate slow mapping
- by Rob A
My question is what can I do to determine the cause of the slowness, or what can I do to speed it up without knowing the exact cause.
I am running a simple query and it appears that the mapping back to the entities is taking taking forever. The result set is 350, which is not much data in my opinion.
IRepository repo = ObjectFactory.GetInstance<IRepository>();
var q = repo.Query<Order>(item => item.Ordereddate > DateTime.Now.AddDays(-40));
foreach (var order in q)
{
Console.WriteLine(order.TransactionNumber);
}
The profiler is telling me it is executing the query 7ms / 35257ms, I am assuming that the former is the actual response from the db and the latter is the time it takes NH to do it's magic.
35 seconds is too long. This is a simple mapping, one table, nested components, using fluent interface to do mappings. I just start up a simple console app and run the one query, the slowness is measured after the SessionFactory is initialized, there should only be one session, and I am not using a transaction.
Thanks