2010/9/22 manish.in.microsoft <[email protected]>: > I have a severe performance problem with Linq for NHibernate that I am > able to reproduce with the Linq for NHibernate unit test cases as > well. Consider the following test case: > > [TestFixture] > public class EntityNameTests : BaseTest > { > [Test] > public void CanQueryOnEntityName() > { > var query = (from e in session.Linq<Person>("person") > where e.Id == 1 > select e); > > var resultList = query.ToList(); > > Assert.That(resultList, > Has.All.AssignableTo(typeof(Person))); > } > } > > When I run this test case, I see the following database query being > fired: > > SELECT this_.Id as Id7_0_, this_.Name as Name7_0_ FROM Person this_ > WHERE this_.Id = @p0;@p0 = 1 > > This is expected. However, if I change the test case to: > > [TestFixture] > public class EntityNameTests : BaseTest > { > [Test] > public void CanQueryOnEntityName() > { > this.RunTest(e => e.Id == 1); > } > > private void Test(Func<Person, bool> predicate) > { > var query = (from e in session.Linq<Person>("person") > where predicate(e) > select e); >
In this case, you are saying: ... where SomeRandomFunctionCallThatMightDoWhateverItLikes(e) ... NHibernate has no choice but to get everything and pass each item to the function. You need to use Expression<Func<T, bool>> instead. /Oskar -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
