1

我正在使用 LINQ to NHibernate 查询 SQLite 数据库。

Person是一个包含 Id 和 Name 的实体:

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

假设我的 db 表包含一个名为“ John ”的人。

此测试按预期工作:

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

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

但是这个失败了:

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());

我错过了什么?

4

1 回答 1

3

调用Where不会更改现有查询,它会创建一个新查询。如果要使用新查询,则需要分配某些内容。

var query2 = query.Where(item => item.Name == "Mike");
于 2010-05-02T19:59:37.927 回答