开发者

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜