XRM ツールを使用してデータを削除

Microsoft Dataverse でデータを削除するために、CrmServiceClient クラスには、DeleteEntity(String, Guid, Guid)DeleteEntityAssociation(String, Guid, String, Guid, String, Guid) の 2 つのメソッドが用意されています。

Microsoft.PowerPlatform.Dataverse.Client 名前空間には、CRUDExtentions.DeleteEntityCRUDExtentions.DeleteEntityAssociation メソッドが存在します。

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 でアクションを実行

注意

ドキュメントの言語設定についてお聞かせください。 簡単な調査を行います。 (この調査は英語です)

この調査には約 7 分かかります。 個人データは収集されません (プライバシー ステートメント)。