Linq to NHibernate using Queryable.Where predicate

Posted by Groo on Stack Overflow See other posts from Stack Overflow or by Groo
Published on 2010-05-02T19:57:10Z Indexed on 2010/05/02 20:08 UTC
Read the original article Hit count: 302

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about linq-to-nhibernate

Related posts about iqueryable