views:

134

answers:

1

I am querying an SQLite database using LINQ to NHibernate.

Person is an entity containing an Id and a Name:

public class Person
{
    public Guid Id { get; private set; }
    public string Name { get; private set; }
}

Let's say my db table contains a single person whose name is "John".

This test works as expected:

var query = from item in session.Linq<Person>()
            where (item.Name == "Mike")
            select item;

// no such entity should exist
Assert.IsFalse(query.Any());

but this one fails:

var query = from item in session.Linq<Person>()
            select item;
query.Where(item => item.Name == "Mike");

// following line actually returns the
// "John" entry
Assert.IsFalse(query.Any());

What am I missing?

+3  A: 

Calling Where doesn't change the existing query, it creates a new one. You need to assign to something if you want to use the new query.

var query2 = query.Where(item => item.Name == "Mike");
Mark Byers
+1 OMG I can't believe I didn't see that. I need a break. Thanks a lot!
Groo