Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过DateTime字段查询DocumentClient时花费的时间太长_C#_Datetime_Azure Cosmosdb_Iso8601 - Fatal编程技术网

C# 通过DateTime字段查询DocumentClient时花费的时间太长

C# 通过DateTime字段查询DocumentClient时花费的时间太长,c#,datetime,azure-cosmosdb,iso8601,C#,Datetime,Azure Cosmosdb,Iso8601,我使用以下代码从DocumentDB数据库获取一些对象的列表: var document = this._client.CreateDocumentQuery<T>(UriFactory.CreateCollectionUri(dbName, collectionName), queryOptions) .Where(r => r.pDate >= startDate && r.pDate <= endDate); var result = doc

我使用以下代码从DocumentDB数据库获取一些对象的列表:

var document = this._client.CreateDocumentQuery<T>(UriFactory.CreateCollectionUri(dbName, collectionName), queryOptions)
.Where(r => r.pDate >= startDate && r.pDate <= endDate);

var result = document.ToList();
var document=this.\u client.CreateDocumentQuery(UriFactory.CreateCollectionUri(dbName,collectionName),queryOptions)

。其中(r=>r.pDate>=startDate&&r.pDate可能是因为应用于此特定字段的索引

从这个链接 , 对于Range或Order by查询,您需要一个范围索引

应用于集合的默认索引策略为 “字符串的哈希和数字的范围”


日期时间存储为字符串,因此对于运行范围比较查询或按顺序查询,您需要将字符串数据类型的索引策略设置为“范围”,精度为-1。

这可能是因为在该特定字段上应用了索引

从这个链接 , 对于Range或Order by查询,您需要一个范围索引

应用于集合的默认索引策略为 “字符串的哈希和数字的范围”


日期时间存储为字符串,因此,要运行范围比较查询或按顺序查询,您需要将索引策略设置为“范围”对于精度为-1的字符串数据类型。

我建议您将日期另存为DateTime,并查看性能是否良好better@MartinoBordin-显然Azure DocumentDB本机不支持
日期时间
…但由于它支持
数字
,也许OP可以尝试将它们存储为历元值。如中所述:。抱歉,我误读了t@hagh已经在使用DateTime进行查询(不是存储,你是对的@Corak)数据。尝试添加一个RangeIndex,如前所述,我建议您将日期保存为DateTime,并查看性能是否正常better@MartinoBordin-显然Azure DocumentDB本机不支持
DateTime
…但由于它确实支持
Number
,或许OP可以尝试将它们存储为历元值。如中所述:。抱歉,我误读了that@hagh已经在使用DateTime来查询(不是存储,你是对的@Corak)数据。请尝试添加RangeIndex,如前所述