英文:
Graph API for email in c# is throwing 0DataError when I order by receivedDateTime
问题
当我取消注释Orderby行时,此代码会引发0DataError异常。
我尝试了不同的大小写,以及使用"desc",但在文档中找不到相关的帮助。
英文:
I have the following c# code:
var result = _userClient
.Users[_email]
.Messages
.GetAsync(conf =>
{
conf.QueryParameters.Filter = QueryFilter;
conf.QueryParameters.Select = new string[] { "id", "receivedDateTime" };
//conf.QueryParameters.Orderby = new string[] { "receivedDateTime asc" };
conf.QueryParameters.Expand = new string[] { "attachments" };
conf.QueryParameters.Top = 1;
})
.Result;
When I uncomment the Orderby line, this code throws a 0DataError exception.
I tried different capitalization, desc and could not find help for this in the documentation.
答案1
得分: 1
使用 $filter
和 $orderby
在同一查询中必须遵循 一些规则 才能正常工作,否则 Graph API 会返回错误 InefficientFilter: The restriction or sort order is too complex for this operation
。
根据这些规则:
- 在
$orderby
中出现的属性也必须在$filter
中出现。 - 在
$orderby
中出现的属性必须与$filter
中的属性顺序相同。 - 在
$orderby
中出现的属性必须在$filter
中的任何未出现的属性之前。
你需要将 receivedDateTime
添加到筛选条件的开头:
string QueryFilter = "receivedDateTime ge 2022-06-26T07:00:00Z and startswith(subject, 'something') and from/emailAddress/address eq 'some@email' and hasAttachments eq true";
var result = _userClient
.Users[_email]
.Messages
.GetAsync(conf =>
{
conf.QueryParameters.Filter = QueryFilter;
conf.QueryParameters.Select = new string[] { "id", "receivedDateTime" };
conf.QueryParameters.Orderby = new string[] { "receivedDateTime asc" };
conf.QueryParameters.Expand = new string[] { "attachments" };
conf.QueryParameters.Top = 1;
})
.Result;
英文:
Using $filter
and $orderby
in the same query must follow some rules to be working, otherwise Graph API returns the error InefficientFilter: The restriction or sort order is too complex for this operation
.
Based on the rules:
- Properties that appear in
$orderby
must also appear in$filter
. - Properties that appear in
$orderby
are in the same order as in$filter
. - Properties that are present in
$orderby
appear in$filter
before any properties that aren't.
You need to add receivedDateTime
at the beginning of the filter:
string QueryFilter = "receivedDateTime ge 2022-06-26T07:00:00Z and startswith(subject, 'something') and from/emailAddress/address eq 'some@email' and hasAttachments eq true"
var result = _userClient
.Users[_email]
.Messages
.GetAsync(conf =>
{
conf.QueryParameters.Filter = QueryFilter;
conf.QueryParameters.Select = new string[] { "id", "receivedDateTime" };
conf.QueryParameters.Orderby = new string[] { "receivedDateTime asc" };
conf.QueryParameters.Expand = new string[] { "attachments" };
conf.QueryParameters.Top = 1;
})
.Result;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论