user14504804
user14504804

Reputation: 859

How to use code to get all properties of a single azure user?

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var delta = await graphClient.Users
    .Delta()
    .Request()
    .Select("displayName,jobTitle,mobilePhone")
    .GetAsync();

I noticed this, is there an easier way to do? Like Select("all property").

Upvotes: 1

Views: 807

Answers (2)

Pashyant Srivastava
Pashyant Srivastava

Reputation: 667

Please try this one to get All :

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var users = await graphClient.Users
.Request()
.GetAsync();

Also Just to add more flavor, You also write your queries like this :

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var users = await graphClient.Users
    .Request()
    .Filter("mail eq '[email protected]'")
    .Select( e => new {
             e.DisplayName,
             e.Mail 
             })
    .GetAsync();

Here you can pass filter criteria if you want to apply. In select clause you can mention the columns which you wanted in output but if you not providing anything in select will give you all.

Microsoft Link for more details : Link

Upvotes: 1

user2250152
user2250152

Reputation: 20823

You can create own helper method that will use reflection to get all properties of type you need and create a select statement from these properties.

public static class Helper
{
    public static IUserDeltaRequest SelectAll(this IUserDeltaRequest request)
    {
        var value = string.Join(",", typeof(User).GetProperties().Where(x => x.PropertyType == typeof(string)).Select(x => x.Name));
        return request.Select(value);
    }
}

I select only properties of type string.

var delta = await graphClient.Users
.Delta()
.Request()
.SelectAll()
.GetAsync();

Upvotes: 1

Related Questions