I'm using the 3.21.0 version of Microsoft.Graph in a .net 5.0 webapi project.
I'd like to provide the possibility to get users page by page but unfortunately the Skip method is not supported for user queries.
The only way to provide paging I found was this:
public class MyController()
{
// Constructors and stuff like that
public async Task<IEnumerable<User>> Get([FromBody] Filter filter)
{
var users = await client.Users
.Request()
.Filter($"startsWith(givenName, '{filter.Pattern}') or startsWith(surname, '{filter.Pattern}')")
.Top(filter.ItemsPerPage)
.GetAsync();
for (int i = 0; i < filter.Page; i++)
{
if (users.NextPageRequest != null)
users = await users.NextPageRequest.GetAsync();
else
{
users = null;
break;
}
}
return users;
}
// Additional methods
}
Is there a better way to reach the goal? Because everytime I call GetAsync() a request is made. The performance would be much better if I only had to call GetAsync() only once.
But as I mentioned before
var users = await client.Users
.Request()
.Filter($"startsWith(givenName, '{filter.Pattern}') or startsWith(surname, '{filter.Pattern}')")
.Skip(filter.Page * filter.ItemsPerPage)
.Top(filter.ItemsPerPage)
.GetAsync();
raises an exception, that Skipis not supported.