views:

155

answers:

2

I use linq to nhibernate and the IQueryable.Where function in an application I'm building. And what mystifies me is how do the Expressions I create and pass to the Where function of a INhibernateQueryable affect performance.

I'm not really sure what are the gotchas I should avoid in writing these query Expressions, in terms of performance. If I pass in an expression with a funtion call like:

CurrentSession.Linq<ENTITY>().Where(x => x.IsBuyOrder && CheckVariousProperties(x))

Is it going to retrieve every record where IsBuyOrder = true and then call the function CheckVariousProperties on them as soon as the deferred execution is no longer deferred?

How do function calls affect LinqToNhibernate performance?

What kind of things should be avoided in a LINQ to Nhibernate query Expression?

A: 

I would eliminate the CheckVariousProperties(x) from the query portion and apply it to the returned result of the query.

var myresult= [object].Where(x => x.IsUBuyOrder);
var checkedResult = myresult.Where(x => CheckVariousProperties(x));
Dave Swersky
thanks for the response, are you saying this will perform better? why?
Mark Rogers
I believe this won't change anything since I think the queries are combined - unless you call ToList() on the first query.
queen3
I'm not even sure combining them would work- wouldn't it have to return the data first, then execute the CheckVariousProperties?
Dave Swersky
A: 

The best thing to do is to profile you're application using NHibernate Profiler. It will be able to help you identify your biggest bottlenecks.

Joseph
Thanks, maybe I'll use it. I was wondering though, do know how linq to nhibernate handles function calls in expressions?
Mark Rogers