Microsoft Graph Client SDK - 按名称过滤组 [英] Microsoft Graph Client SDK -filter groups by name

查看:69
本文介绍了Microsoft Graph Client SDK - 按名称过滤组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个相当简单的问题,但我无法将查询图形的基本 httpClient 方法转换为 SDK 方法.我正在使用以下内容并且效果很好:

A rather simple ask but I'm having trouble converting my basic httpClient method of querying the Graph into the SDK method. I was using the following and it works fine:

    var filter = "IT";
    var response = await httpClient.GetAsync($"{webOptions.GraphApiUrl}/beta/groups?$filter=startswith(displayName, '{filter}')&$select=id,displayName");

...现在我正在尝试使用 SDK 进行过滤,如下所示:

...now I'm attempting to filter using the SDK as follows:

    var groups = await graphServiceClient.Groups
        .Request()
        .Filter($"displayName startswith {filter}")
        .Select("id, displayName")
        .GetAsync();

我也尝试过 .Filter($"startswith("displayName", {filter})) 和其他变体.

I've also tried .Filter($"startswith("displayName", {filter})) and other variants.

我收到一个无效过滤器子句错误.有什么想法吗?

I'm getting an invalid filter clause error. Any ideas?

推荐答案

显然是因为为 Filter 方法提供的过滤器表达式无效,可以这样验证:

Apparently it occurs since the provided filter expression for Filter method is invalid, it could be validated like this:

var message = graphServiceClient.Groups
        .Request()
        .Filter($"displayName startswith '{filter}'")
        .Select("id, displayName").GetHttpRequestMessage();

生成的 message.RequestUri 将返回以下值:

The generated message.RequestUri will return the following value:

https://graph.microsoft.com/v1.0/groups?$filter=displayName startswith '{filter}'&$select=id, displayName}

需要像这样指定有效的过滤器表达式:

A valid filter expression needs to be specified like this:

.Filter($"startswith(displayName, '{filter}')")

如果您想为 GraphServiceClient 类切换到 beta 版本,可以这样指定:

In case if you want to switch to beta version for GraphServiceClient class, it could be specified like this:

graphServiceClient.BaseUrl = "https://graph.microsoft.com/beta";  

这篇关于Microsoft Graph Client SDK - 按名称过滤组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆