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].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to