【发布时间】:2017-05-21 21:14:11
【问题描述】:
我刚刚开始使用 DocumentDB/Cosmos,遇到了一个错误,我不确定这是我做的还是错误。为了便于测试,我使用 DocumentDB 模拟器 V1.13.58.2 和 C# DocumentDB SDK V1.14.0。
一切正常,直到我尝试执行 Linq 查询,在该查询中我对 id 以外的文档属性进行相等性测试。如果我使用 id 则它可以工作,否则 DocumentDB 服务器会崩溃。我还尝试降级到 SDK 的 V1.13.4,它会抛出异常“解析值时遇到意外字符:≻.Path '', line 0, position 0”。
下面是我用来创建问题的代码。
首先我创建了一个简单的类来使用,然后我将一些实例添加到数据库中。我可以看到在文档资源管理器中使用正确的分区成功创建了文档。
public class TestEntityClass
{
[JsonProperty(PropertyName = "id")]
public Guid Id { get; set; }
[JsonProperty(PropertyName = "type")]
public int DocumentType { get; set; }
[JsonProperty(PropertyName = "pId")]
public string PartitionId { get; set; }
[JsonProperty(PropertyName = "stringProperty")]
public string StringProperty { get; set; }
[JsonProperty(PropertyName = "numberProperty")]
public int NumberProperty { get; set; }
}
然后我尝试使用 linq 查询数据库,其中“match”是一个 Linq 表达式。
using (var query = m_Client.CreateDocumentQuery<TObject>(UriFactory.CreateDocumentCollectionUri(m_DBName, m_ColName),
new FeedOptions() { MaxItemCount = 1 }).Where(m => m.PartitionId == PartitionId && m.DocumentType == m_Type)
.Where(match).AsDocumentQuery())
{
var response = await query.ExecuteNextAsync<TObject>();
if (response.Count == 0) { return null; }
return response.ElementAt(0);
}
当我将匹配设置为
match = m => m.Id == entity1.Id;
效果很好。
但是,如果我将匹配设置为
match = m => m.NumberProperty == entity1.NumberProperty;
或
match = m => m.StringProperty == entity1.StringProperty;
DocumentDb 服务器崩溃。
现在所有这些都在我的云托管 Cosmos 数据库上运行良好,所以这不是一个大问题,但我只是好奇这是我正在做的事情还是只是一个错误。如果有人有任何见解,我将不胜感激。谢谢。
【问题讨论】:
标签: c# linq emulation azure-cosmosdb