英文:
Graph explorer C# snippets do not work with Microsoft.Graph" Version="5.9.0"
问题
为了仅获取选定字段,我在图形资源管理器中进行测试:
https://graph.microsoft.com/v1.0/sites/372ddaf5-60a1-46d4-bb19-2f80c9ba32b3/lists/DPC-Job-Master/items?expand=fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)&$filter=fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null
它能够正常工作。代码片段如下:
var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string []{ "fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
在我的代码中使用这个片段时,出现了错误:
"解析 OData Select 和 Expand 失败:术语 '(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)' 在 $select 或 $expand 表达式中无效。"
有没有更好的方法找出可行的语法?
谢谢
英文:
To get just selected fields, I test in Graph explorer
https://graph.microsoft.com/v1.0/sites/372ddaf5-60a1-46d4-bb19-2f80c9ba32b3/lists/DPC-Job-Master/items?expand=fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)&$filter=fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null
it works fine. the snippet is:
var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string []{ "fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
When using the snippet in my code it failes with:
"Parsing OData Select and Expand failed: Term '(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)' is not valid in a $select or $expand expression."
Is there a better way to figure out the syntax that will work?
Thank you
答案1
得分: 2
If you try to get request information and check what URL is generated by 5.9.0:
var request = graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.ToGetRequestInformation((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string[] { "fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
result.URI.AbsoluteUri
has the value:
https://graph.microsoft.com/v1.0/sites/%7Bsite-id%7D/lists/%7Blist-id%7D/items?%24filter=fields%2FCompletion%20gt%20%272023-05-04T09%3A15%3A32.6473018Z%27%20and%20fields%2FCurrentQueue%20eq%20%27Done%27%20and%20fields%2FDoneReceived%20eq%20null&%24expand=fields%28select%3DTitle%2CRequestForLookupId%2CCompletion%2CCurrentQueue%2CDoneReceived%29
Decoded:
https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$filter=fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null&$expand=fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)
You can see that the SDK generates $expand
instead of expand
.
As a quick fix, you can use $select
inside Expand
:
var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
// $select instead of select
requestConfiguration.QueryParameters.Expand = new string[] { "fields($select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
英文:
If you try to get request information and check what url is generated by 5.9.0
var request = graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.ToGetRequestInformation((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string[] { "fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
result.URI.AbsoluteUri
has the value
https://graph.microsoft.com/v1.0/sites/%7Bsite-id%7D/lists/%7Blist-id%7D/items?%24filter=fields%2FCompletion%20gt%20%272023-05-04T09%3A15%3A32.6473018Z%27%20and%20fields%2FCurrentQueue%20eq%20%27Done%27%20and%20fields%2FDoneReceived%20eq%20null&%24expand=fields%28select%3DTitle%2CRequestForLookupId%2CCompletion%2CCurrentQueue%2CDoneReceived%29
Decoded
https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$filter=fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null&$expand=fields(select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)
You can see that SDK generates $expand
instead of expand
.
As a quick fix you can use $select
inside Expand:
var result = await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items.GetAsync((requestConfiguration) =>
{
// $select instead of select
requestConfiguration.QueryParameters.Expand = new string []{ "fields($select=Title,RequestForLookupId,Completion,CurrentQueue,DoneReceived)" };
requestConfiguration.QueryParameters.Filter = "fields/Completion gt '2023-05-04T09:15:32.6473018Z' and fields/CurrentQueue eq 'Done' and fields/DoneReceived eq null";
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论