You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Microsoft Graph API SDK请求中指定OdataType为microsoft.graph.group?

在Microsoft Graph SDK中指定仅获取组类型的transitiveMemberOf结果

你可以通过SDK的类型筛选方法直接在请求阶段获取组类型的结果,不需要本地过滤,对应你在Graph Explorer中使用的/microsoft.graph.group路径段,有两种常用实现方式:

方式一:使用OfType<Group>()方法(推荐)

这种写法完全对应你Graph Explorer中的请求逻辑,会直接调用Graph API的组类型专属端点,返回的结果直接是Group对象集合:

await this._graphServiceClient.Users[userId].TransitiveMemberOf.OfType<Group>().Request().Select(this.GetQuery()).GetAsync();

方式二:使用Filter筛选odata类型

如果需要更灵活的类型筛选,也可以通过Filter条件指定只返回组类型的对象:

await this._graphServiceClient.Users[userId].TransitiveMemberOf.Request()
    .Filter("odata.type eq '#microsoft.graph.group'")
    .Select(this.GetQuery())
    .GetAsync();

两种方式都是在服务器端完成筛选,避免了本地处理额外数据的开销,其中第一种方式更贴合你原本的请求路径,性能表现更优。

内容的提问来源于stack exchange,提问作者Antoine Brisebois-Roy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:54:20