我试图从 Microsoft Graph 获取 this documentation 之后的事件列表.
我想按 lastModifiedDateTime
然后按 id
获取列表。
这是示例查询:
var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime, id", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));
但是,当我执行它时,它会导致错误:
{
"error": {
"code": "ErrorInvalidProperty",
"message": "The property 'Id' does not support filtering.",
"innerError": {
"request-id": "bb56a0d0-46f3-4b7c-80bd-043a0b3fd8b5",
"date": "2018-09-17T15:23:40"
}
}
}
事实上,我并没有在$filter
中设置Id
,而是将其设置为$orderby
。
当我尝试从 $orderby
中排除 Id
时,它起作用了。这是工作查询:
var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));
有人知道如何根据 Id
对列表进行排序吗?
最佳答案
您不能通过 id
进行排序,这样做也没有任何意义。 id
是几个属性(主题、路径等)的散列组合。因此,它们的值(value)既不可订购也不可读。
例如,这是一个实际的 id
值:
AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OABGAAAAAAAiQ8W967B7TKBjgx9rVEURBwAiIsqMbYjsT5e-T7KzowPTAAAAAAENAAAiIsqMbYjsT5e-T7KzowPTAACNM9xPAAA=
此外,我强烈建议使用 Microsoft Graph .NET Client而不是自己滚动。这将有助于减少学习曲线并为您提供更具可读性的代码:
await graphClient.Me
.Calendar
.Events
.Request()
.Filter("lastModifiedDateTime ge {dateTime}")
.OrderBy("lastModifiedDateTime")
.GetAsync();
关于c# - Outlook 事件列表的 OData 无法按 "Id"排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52389666/