C# DocumentDB Emulator在Linq查询上崩溃
我刚刚开始使用DocumentDB/Cosmos,遇到了一个错误,我不确定这是我做的还是一个bug。为了便于测试,我使用了DocumentDB emulator V1.13.58.2和C#DocumentDB SDK V1.14.0 在我尝试执行Linq查询之前,一切都正常。在Linq查询中,我对id以外的文档属性进行了相等性测试。如果我使用id,则一切正常,否则DocumentDB服务器将崩溃。我还尝试降级到SDK的V1.13.4,它抛出一个异常“解析值时遇到意外字符:≻. 路径“”,第0行,位置0” 下面是我用来创建问题的代码 首先,我创建了一个简单的类来使用它,然后将一些实例添加到数据库中。我可以看到在文档资源管理器中使用正确的分区成功创建了文档C# DocumentDB Emulator在Linq查询上崩溃,c#,linq,emulation,azure-cosmosdb,C#,Linq,Emulation,Azure Cosmosdb,我刚刚开始使用DocumentDB/Cosmos,遇到了一个错误,我不确定这是我做的还是一个bug。为了便于测试,我使用了DocumentDB emulator V1.13.58.2和C#DocumentDB SDK V1.14.0 在我尝试执行Linq查询之前,一切都正常。在Linq查询中,我对id以外的文档属性进行了相等性测试。如果我使用id,则一切正常,否则DocumentDB服务器将崩溃。我还尝试降级到SDK的V1.13.4,它抛出一个异常“解析值时遇到意外字符:≻. 路径“”,第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;
或
DocumentDb服务器崩溃
现在所有这些都可以在我的云托管的Cosmos数据库上正常工作,所以这不是一个大问题,但我只是好奇这是我正在做的事情还是一个bug。如果有人有任何见解,我将不胜感激。谢谢。我创建了一个控制台应用程序并连接到Azure Cosmos DB Emulator实例,我可以根据id属性和其他属性查询和筛选文档 类TestEntityClass(与您的相同): packages.config
注意:如果跨分区执行查询,则设置EnableCrossPartitionQuery=true
请尝试在
CreateDocumentQuery
中使用TestEntityClass
,而不是CreateDocumentQuery
,并检查是否出现相同的错误。哼哼,我在另一台计算机上尝试了这一方法,效果也不错。然后我试着运行我的原始代码,它也在这台计算机上运行。我的另一台计算机上的环境一定有问题。谢谢你的时间和帮助。
match = m => m.StringProperty == entity1.StringProperty;
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; }
}
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.DocumentDB" version="1.14.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
</packages>