开发者

NHibernate slow mapping

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 conso开发者_运维问答le 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


If your database query is returning quickly, then the problem is somewhere in the code itself. It's unlikely to be in NHibernate. Your comments imply that you are using custom user types, and it may very well be that there's something particularly inefficient in there. I am guessing you are using NHProf as your profiler? Perhaps you should use a straight .NET profiler and look at the performance of the code itself, including these custom types? Something like Ants, dotTrace or AQTime.


It is likely that you are doing something in your user types that takes a lot of time


Try disabling log4net. If it speeds things up and you still want to use it for other purposes, disable only nhibernate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜