'Department not null filter for IGraphServiceUsersCollectionRequest (GraphServiceClient)
How to create not null filter for department property to get users by GraphServiceClient?
department ne null
and
NOT(department eq null)
don't work
My current code:
var request = _graphClient.Users.Request()
.Filter($"department ne null");
var usersPage = await request.GetAsync();
Solution 1:[1]
Filtering by department requires adding header ConsistencyLevel:eventual and $count parameter must be set to true.
According to the documentation department is returned only on $select. It means that if you need to know the value of department you have to add Select method and specify all properties to be returned including department.
var queryOptions = new List<QueryOption>()
{
new HeaderOption("ConsistencyLevel", "eventual");
new QueryOption("$count", "true")
};
var request = await _graphClient.Users
.Request( queryOptions )
.Select("id,displayName,department") // and other properties
.Filter("department ne null"); // .Filter("NOT(department eq null)") should also work
var usersPage = await request.GetAsync();
Resources:
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 | user2250152 |
