XRM ツールを使用してデータを削除
Microsoft Dataverse でデータを削除するために、CrmServiceClient クラスには、DeleteEntity(String, Guid, Guid) と DeleteEntityAssociation(String, Guid, String, Guid, String, Guid) の 2 つのメソッドが用意されています。
Microsoft.PowerPlatform.Dataverse.Client 名前空間には、CRUDExtentions.DeleteEntity と CRUDExtentions.DeleteEntityAssociation メソッドが存在します。
アプリケーション コードでの接続文字列の使用については、次の重要な情報をお読みください。
重要
Microsoft では、利用可能な最も安全な認証フローを使用することをお勧めします。 この記事で説明する認証フローは、アプリケーションに対する非常に高い信頼を必要とし、他のフローには存在しないリスクを伴います。 このフローは、マネージド ID など、他のより安全なフローが実行できない場合にのみ使用してください。
DeleteEntity
DeleteEntity
は、Dataverse から単一のデータ行を削除する場合に使用します。 このメソッドを使用するには、影響を与えるテーブル スキーマ名と、削除する行の GUID を知っている必要があります。
CrmServiceClient svc = new CrmServiceClient(connectionstring);
// ServiceClient svc = new ServiceClient("connectionstring");
// Verify that you are connected
if (svc != null && svc.IsReady)
{
// Delete the entity record
svc.DeleteEntity("account", <accountId>);
}
else
{
// Display the last error.
Console.WriteLine("An error occurred: {0}", svc.LastCrmError);
// Display the last exception message if any.
Console.WriteLine(svc.LastCrmException.Message);
Console.WriteLine(svc.LastCrmException.Source);
Console.WriteLine(svc.LastCrmException.StackTrace);
return;
}
DeleteEntityAssociation
DeleteEntityAssociation
は、テーブル内のレコード間の多対多の関連付けを削除します。 この例では、リード テーブルとアカウント テーブルのレコード間の関連付けを削除します。
CrmServiceClient svc = new CrmServiceClient(connectionstring);
// ServiceClient svc = new ServiceClient("connectionstring");
// Verify that you are connected
if (svc != null && svc.IsReady)
{
Guid accountId = new Guid("<Account_GUID>");
Guid leadId = new Guid("<Lead_GUID>");
string accountLeadRelationshipName= "accountleads_association";
svc.DeleteEntityAssociation("account" , accountId, "lead" , leadId, accountLeadRelationshipName)
}
else
{
// Display the last error.
Console.WriteLine("An error occurred: {0}", svc.LastCrmError);
// Display the last exception message if any.
Console.WriteLine(svc.LastCrmException.Message);
Console.WriteLine(svc.LastCrmException.Source);
Console.WriteLine(svc.LastCrmException.StackTrace);
return;
}
参照
XRM ツールを使用して Dataverse に接続する
XRM ツール API を使用して Dataverse でアクションを実行