您可以使用microsoft graph sdk v1.4.0版本創建架構擴展。相關討論&代碼示例here和here僅供參考。
例如,爲了創建用於基的架構擴展:
// 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
屬性中。