在 MS Graph API v1.0 中查找用户的变量插值问题

Variable interpolation issue in finding users in MS Graph API v1.0

我正在使用以下代码搜索用户详细信息:

 var users2 = await graphServiceClient.Users.
   .Request()
   .Filter("startswith(displayName,'Robert')")
   .Select(u => new {
       u.DisplayName,
       u.MobilePhone,
       u.UserPrincipalName
   }).GetAsync();

它有效,但是当我使用下面的代码并尝试将用户显示名称存储在一个字符串中,然后 运行 查询它时 returns null。

 string dispName = mem.DisplayName;

    var users2 = await graphServiceClient.Users
   .Request()
   .Filter("startswith(displayName,'{dispName}')")
   .Select(u => new {
       u.DisplayName,
       u.MobilePhone,
       u.UserPrincipalName
   })
   .GetAsync();

我也用 $'{dispName}' 试过,它不起作用。 请帮忙。

根据$ - string interpolation

应该是这样的
    string dispName = mem.DisplayName;

    var users2 = await graphServiceClient.Users
   .Request()
   .Filter($"startswith(displayName,'{dispName}')")
   .Select(u => new {
       u.DisplayName,
       u.MobilePhone,
       u.UserPrincipalName
   })
   .GetAsync();

请参考$filter to know more about filter parameter