RavendbC#API:如何在服务器端执行查询筛选

RavendbC#API:如何在服务器端执行查询筛选,c#,ravendb,nosql,C#,Ravendb,Nosql,我的Raven数据库中有128多个文件,类型为Foo: class Foo { public string Id {get; set;} public string Name {get; set;} } 对于两个文档,Name属性具有值“MyName” 对于IDocumentSession会话,如果执行session.query(),其中(f=>f.Name.equals(“MyName”),则得到的结果为零。这似乎是因为从RavenDB服务器返回的128个文档(默认客户端页面大小)中

我的Raven数据库中有128多个文件,类型为
Foo

class Foo {
  public string Id {get; set;}
  public string Name {get; set;}
}
对于两个文档,
Name
属性具有值
“MyName”

对于
IDocumentSession会话
,如果执行
session.query(),其中(f=>f.Name.equals(“MyName”)
,则得到的结果为零。这似乎是因为从RavenDB服务器返回的128个文档(默认客户端页面大小)中没有返回与“MyName”匹配的两个文档。因此,客户端API通过
Name==“MyName”
对返回的128个文档进行过滤,但是由于我的两个匹配文档不在前128个文档中,因此没有找到匹配的文档。我用1验证了这个假设。在浏览器中查看我的RavenDb studio并验证这两个文档是否存在,以及2。通过实现无边界流式查询并成功检索这两个文档:

var results = new List<Foo>();
var query = session.Query<Foo>().Where(f => f.Name.equals("MyName");
using (var enumerator = session.Advanced.Stream(query){
  while (enumerator.MoveNext()){
    results.Add(enumerator.Current.Document);
  }
}
var results=newlist();
var query=session.query(),其中(f=>f.Name.equals(“MyName”);
使用(var枚举器=session.Advanced.Stream)(查询){
while(枚举数.MoveNext()){
结果.Add(枚举器.Current.Document);
}
}

然而,流媒体解决方案对我来说并不理想。我的问题是:在将128个文档返回到客户端之前,有没有办法让RavenDB在服务器上对Name执行过滤?我想在数据库中的所有文档中搜索给定的
Where
过滤器,但一旦应用了过滤器,我就完全是c了让服务器返回的内容您的假设是不正确的。默认页面大小适用于查询结果,而不适用于您正在查询的文档集合(如果这是真的,将导致左右严重的问题,因为您无法控制集合中的先到和后到内容)

您是否正在实际执行查询(即调用
query.ToList()
或类似的东西)?-如果执行,请提供显示查询和分配结果的进一步代码

编辑

因此,这在我的机器上可以正常工作:

[TestFixture]
public class UnitTest3
{
    public class Foo
    {
        public string Id { get; set; }
        public string Name { get; set; }
    }

    private readonly IDocumentStore _documentStore;

    public UnitTest3()
    {
        _documentStore = new EmbeddableDocumentStore
        {
            Configuration =
            {
                RunInUnreliableYetFastModeThatIsNotSuitableForProduction = true,
                RunInMemory = true,
            }
        }.Initialize();
    }

    public void InsertDummies()
    {
        using (IDocumentSession session = _documentStore.OpenSession())
        {
            for (int i = 0; i < 1000; i++)
            {
                Foo foo = new Foo { Name = "Foo" + i };
                session.Store(foo);
            }

            Foo fooA = new Foo { Name = "MyName"};
            session.Store(fooA);
            Foo fooB = new Foo { Name = "MyName" };
            session.Store(fooB);

            session.SaveChanges();
        }
    }

    [Test]
    public void Query()
    {
        List<Foo> result;
        InsertDummies();
        using (IDocumentSession session = _documentStore.OpenSession())
        {
            result = session.Query<Foo>().Where(f => f.Name.Equals("MyName")).ToList();
        }
        Assert.AreEqual(2, result.Count);
    }
}
[TestFixture]
公共类UnitTest3
{
公开课Foo
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
}
私有只读IDocumentStore\u documentStore;
公共单元测试3()
{
_documentStore=新嵌入的documentStore
{
配置=
{
RuninUnreliableyeTFastMode不适用于生产=真,
RunInMemory=true,
}
}.Initialize();
}
公共void InsertDummies()
{
使用(IDocumentSession=\u documentStore.OpenSession())
{
对于(int i=0;i<1000;i++)
{
Foo-Foo=newfoo{Name=“Foo”+i};
session.Store(foo);
}
Foo fooA=新Foo{Name=“MyName”};
session.Store(fooA);
Foo fooB=new Foo{Name=“MyName”};
会话存储(fooB);
session.SaveChanges();
}
}
[测试]
公共无效查询()
{
列出结果;
插入假人();
使用(IDocumentSession=\u documentStore.OpenSession())
{
result=session.Query().Where(f=>f.Name.Equals(“MyName”)).ToList();
}
Assert.AreEqual(2,result.Count);
}
}

你检查过索引是否过时了吗?

该方法基本上返回
List
,我返回
query.ToList()
。谢谢,我认为这不可能是对的。今天我将进一步研究它,看看我是否能找出为什么会出现这种行为。