Linq to NHibernate using Queryable.Where predicate
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开发者_JAVA百科());
What am I missing?
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");
精彩评论