For this kind of matter NHibernate give you six systems to query your domain instead just once. Btw you are doing it in the wrong way; you have to use Expression<Func<T, bool>> instead Func<T, bool> and perhaps you can even avoid the framework: http://linqspecs.codeplex.com/
On Wed, Sep 22, 2010 at 6:59 AM, manish.in.microsoft < [email protected]> wrote: > 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); > > var resultList = query.ToList(); > > Assert.That(resultList, > Has.All.AssignableTo(typeof(Person))); > } > } > > I get the following SQL: > > SELECT this_.Id as Id7_0_, this_.Name as Name7_0_ FROM Person this_ > > I am trying to write a generic framework that uses Linq for NHibernate > where I will have to pass the predicate to a generic class. I do not > want to incur the performance penalty of fetching all rows when this > generic class is called. Any suggestions? > > -- > 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]<nhusers%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > > -- Fabio Maulo -- 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.
