2017-06-21 101 views
1

我們已經使用Microsoft Graph API一段時間來設置擴展屬性的值。以前我們使用過Microsoft.Azure.ActiveDirectory.GraphClient,但是一年之後就有了一個Microsoft.Graph Nuget包。使用Microsoft.Azure.ActiveDirectory.GraphClient時,有一種名爲SetExtendedProperty的方法,但Microsoft.Graph包中沒有這種東西。有沒有人有建議如何設置擴展屬性與Microsoft.Graph包?Microsoft.Graph api設置用戶擴展屬性

如果您需要更多信息,請讓我知道!

回答

2

您可以使用microsoft graph sdk v1.4.0版本創建架構擴展。相關討論&代碼示例herehere僅供參考。

例如,爲了創建用於基的架構擴展:

// Create a schema extension for groups. 
SchemaExtension extensionDefinition = new SchemaExtension() 
{ 
    Description = "This extension correlates a group with a foreign database.", 
    Id = $"crmForeignKey", // Microsoft Graph will prepend 8 chars 
    Properties = new List<ExtensionSchemaProperty>() 
    { 
     new ExtensionSchemaProperty() { Name = "fid", Type = "Integer" } 
    }, 
    TargetTypes = new List<string>() 
    { 
     "Group" 
    } 
}; 

// Create the schema extension. This results in a call to Microsoft Graph. 
SchemaExtension schemaExtension = await graphClient.SchemaExtensions.Request().AddAsync(extensionDefinition); 

然後用於擴展創建類:

[JsonObject(MemberSerialization = MemberSerialization.OptIn)] 
public class MyDBExtensionClass 
{ 
    [JsonProperty(NullValueHandling = NullValueHandling.Ignore, PropertyName = "fid", Required = Newtonsoft.Json.Required.Default)] 
    public int FID { get; set; } 

    public MyDBExtensionClass(int fid) 
    { 
     FID = fid; 
    } 
} 

接着,更新設置的架構擴展屬性到一個存在的組AdditionalData性質組別:

 // Update a group. 
     // This snippet changes the group name. 
     // This snippet requires an admin work account. 
     public async Task<List<ResultsItem>> UpdateGroup(GraphServiceClient graphClient, string id, string name) 
     { 
      List<ResultsItem> items = new List<ResultsItem>(); 
      IDictionary<string, object> extensionInstance = new Dictionary<string, object>(); 
      extensionInstance.Add(extensionIDYouGet, new MyDBExtensionClass(1213)); 
      // Update the group. 
      await graphClient.Groups[id].Request().UpdateAsync(new Group 
      { 
       DisplayName = Resource.Updated + name, 
       AdditionalData= extensionInstance 
      }); 

      items.Add(new ResultsItem 
      { 

       // This operation doesn't return anything. 
       Properties = new Dictionary<string, object> 
       { 
        { Resource.No_Return_Data, "" } 
       } 
      }); 
      return items; 
     } 

您還可以添加如上圖所示,擴展到一個新的創建組。

更新:

你的要求設置架構擴展性能,用戶,然後更新的用戶AdditionalData屬性:

await graphClient.Users["ID"].Request().UpdateAsync(new User 
      { 
       DisplayName = Resource.Updated + name, 
       AdditionalData = extensionInstance 

      }); 

如果你想創建一個用戶實體架構擴展,User值應包含在SchemaExtension對象的TargetTypes屬性中。