'MS Graph filtering by companyName doesn't work

I have two similar fragments:

IGraphServiceUsersCollectionPage users = await graphServiceClient.Users
    .Request()
    .Select("id")
    .Filter("department eq 'Department'")
    .GetAsync();

and

IGraphServiceUsersCollectionPage users = await graphServiceClient.Users
    .Request()
    .Select("id")
    .Filter("companyName eq 'CompanyName'")
    .GetAsync();

The first fragment works correctly; the second fragment doesn't work at all.

I have success with direct request via HTTP GET

https://graph.microsoft.com/beta/users?ConsistencyLevel=eventual&$count=true&$filter=companyName eq 'Company'

So now I have a question: how I can do it with MSGraph API in C#?



Solution 1:[1]

To add $count=true to your query you should use QueryOption

var options = new List<QueryOption>();
options.Add(new QueryOption("$count", "true"));
IGraphServiceUsersCollectionPage users = await graphServiceClient.Users
    .Request(options)
    .Select("id")
    .Filter("companyName eq 'CompanyName'")
    .GetAsync();

Advanced query capabilities on Azure AD directory objects

Query parameters to customize query

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Maxim