移除了属性的 RavenDB 查询文档 [英] RavenDB Query Documents with Property Removed

查看:55
本文介绍了移除了属性的 RavenDB 查询文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 RavenDB Studio 中,我可以看到 69 个 CustomVariableGroup 文档.我的查询只返回其中的 66 个.经过一番挖掘,我发现返回的三个文档具有新的类结构:删除了一个属性.由于我保存了这三个 CustomVariableGroup 文档,它们的结构与其他 66 个文档不同.为什么当我查询所有这些文档时,我只能得到其他 66 个具有旧结构的文档?

In the RavenDB Studio, I can see 69 CustomVariableGroup documents. My query only returns 66 of them. After some digging, I see that the three docs that are not returned have the new class structure: a property was removed. Since I saved these three CustomVariableGroup documents, their structure is different from the other 66. Why though, when I query for all of them, do I only get the other 66 documents with the old structure?

我的 C# 代码和我在 LinqPad 中的查询都只返回 66.这是 LinqPad 查询:

Both my C# code, and my query in LinqPad, only return the 66. Here's the LinqPad query:

Session.Query<CustomVariableGroup>().Dump();  // returns 66 docs

但是,如果我这样做,我可以获得上述查询中缺少的三个文档之一:

But, if I do this, I can get one of the three documents that is missing from the above query:

Session.Query<CustomVariableGroup>().Where(x => x.Name == "Derating").Dump();

如何在一次查询中获取所有 69 个文档?

How can I get all 69 documents returned in one query?

** 索引信息 **

在 LinqPad 查询(以及 Raven 服务器输出)的 SQL 选项卡中,索引如下所示:

In the SQL tab of the LinqPad query (and in the Raven server output), the index looks like this:

网址:/indexes/dynamic/CustomVariableGroups?query=&start=0&pageSize=128&aggregation=None

Url: /indexes/dynamic/CustomVariableGroups?query=&start=0&pageSize=128&aggregation=None

我在 Raven Studio 中没有看到该索引,大概是因为它是动态的.

I don't see that index in Raven Studio, presumably because it's dynamic.

** 编辑 2:此 HACK 有效 **

** Edit 2: This HACK works **

如果我这样做,我会得到所有 69 个文件:

If I do this, I get all 69 documents:

Session.Query<CustomVariableGroup>().Where(x => x.Name != string.Empty).Dump();

我的猜测是 Raven 必须使用旧索引,该索引仅获取仍包含已删除列的文档.我不知何故需要使用一个新的/不同的索引...

My guess is that Raven must be using an old index that only gets documents that still contain that deleted column. I somehow need to use a new/different index...

有趣的是,这是行不通的;它只返回 66:

Interestingly, this does not work; it only returns 66:

Session.Query<CustomVariableGroup>().Where(x => x.Id != string.Empty).Dump();

** 编辑 3:这个 HACK 也适用 **

** Edit 3: This HACK works as well **

Session.Advanced.LuceneQuery<CustomVariableGroup>("Raven/DocumentsByEntityName").Where("Tag:CustomVariableGroups").Dump();

推荐答案

必须删除具有旧属性的索引.

An index, with the old property, had to be removed.

** 之前 ** 这不起作用(仅返回 69 个文档中的 66 个):

** Before ** This didn't work (only returned 66 of the 69 documents):

Session.Query<CustomVariableGroup>().Dump();

** 修复 ** 删除使用从我的 C# 类中删除的旧属性的索引:

在 Raven Studio 中,我删除了这个索引:Auto/CustomVariableGroups/ByApplicationId

In Raven Studio, I deleted this index: Auto/CustomVariableGroups/ByApplicationId

** After ** 这个相同的查询现在返回所有 69 个文档:

** After ** This same query now returns all 69 documents:

Session.Query<CustomVariableGroup>().Dump();

现在,我不确定为什么这些查询会使用该索引.我正在查询所有 CustomVariableGroup 文档,而不是 ByApplicationId.但是,删除该索引修复了它.我相信其他人可以解释原因.

Now, I'm not sure why these queries would use that index. I'm querying for all CustomVariableGroup documents, and not ByApplicationId. However, removing that index fixed it. I'm sure someone else can explain why.

这篇关于移除了属性的 RavenDB 查询文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆