You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: powerapps-docs/developer/data-platform/org-service/entity-operations-associate-disassociate.md
+18-78Lines changed: 18 additions & 78 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Associate and disassociate table rows using the SDK for .NET (Microsoft Dataverse) | Microsoft Docs"# Intent and product brand in a unique string of 43-59 chars including spaces
3
3
description: "Learn how to associate and disassociate table rows using the SDK for .NET"# 115-145 characters including spaces. This abstract displays in the search result.
4
-
ms.date: 03/22/2022
4
+
ms.date: 12/13/2024
5
5
ms.reviewer: "pehecke"
6
6
ms.topic: "article"
7
7
author: MicroSri
@@ -19,9 +19,9 @@ contributors:
19
19
20
20
Table rows are associated to each other using lookup columns on the related table row. The simplest way to associate two rows in a one-to-many relationship is to use an <xref:Microsoft.Xrm.Sdk.EntityReference> to set the value of a lookup column on the related row.
21
21
22
-
The simplest way to disassociate two rows in a one-to-many relationship is to set the value of the lookup column to null.
22
+
The simplest way to disassociate two rows in a one-to-many relationship is to set the value of the lookup column to `null`.
23
23
24
-
Relationships using an many-to-many relationship also depend on lookup columns on the *intersect entity* that supports the many-to-many relationship. These relationship are defined by the existence of rows in that intersect entity. While you can interact with the intersect entity directly, it is much easier to use the API to do this for you.
24
+
Relationships using a many-to-many relationship also depend on lookup columns on the *intersect entity* that supports the many-to-many relationship. Relationship are defined by the existence of rows in that intersect entity. While you can interact with the intersect entity directly, it's much easier to use the API to do this task for you.
25
25
26
26
## Use the Associate method or AssociateRequest
27
27
@@ -40,109 +40,49 @@ Whether the relationship is a one-to-many or many-to-many relationship doesn't m
40
40
41
41
You can discover the names of the relationships by viewing the customization UI or in the metadata using the Metadata Browser.
42
42
43
-
More information:
43
+
More information:
44
44
45
45
-[Create and edit 1:N (one-to-many) or N:1 (many-to-one) relationships](../../../maker/data-platform/create-edit-1n-relationships.md)
46
46
-[Create and edit many-to-many (N:N) table row relationships](../../../maker/data-platform/create-edit-nn-relationships.md)
47
47
-[Browse the metadata for your environment](../browse-your-metadata.md)
48
48
49
-
The following example will set a specific contact (`jimGlynn`) as the primary contact for all accounts that are in Redmond.
49
+
The following example creates a relationship and associates a primary entity with a collection of related entities.
Although there is no particular advantage in doing so, if you wanted to use the <xref:Microsoft.Xrm.Sdk.Messages.AssociateRequest>, you can replace the last line with this:
81
-
54
+
If you wanted to use the <xref:Microsoft.Xrm.Sdk.Messages.AssociateRequest>, you would use the following code. A benefit of using the request instead of the service client method is that the request supports the [use of optional parameters](../optional-parameters.md).
82
55
83
56
```csharp
84
-
// Use AssociateRequest
85
57
AssociateRequestrequest=newAssociateRequest()
86
58
{
87
-
RelatedEntities=accountReferences,
88
-
Relationship=relationship,
89
-
Target=jimGlynn
59
+
RelatedEntities=relatedEntities,
60
+
Relationship=relation,
61
+
Target=primaryEntity
90
62
};
91
63
92
-
svc.Execute(request);
64
+
service.Execute(request);
93
65
```
94
66
95
-
This operation is the same as three separate update operations to the [Account](../reference/entities/account.md).[PrimaryContactId](../reference/entities/account.md#BKMK_PrimaryContactId) lookup column, but it is using the [account_primary_contact](../reference/entities/contact.md#BKMK_account_primary_contact) relationship, which is a many-to-one entity relationship on the account and a one-to-many entity relationship on the contact.
67
+
Let's say we are associating a primary entity (a contact) with three related entities (accounts). This single association operation shown above is the same as three separate update operations where the [Account](../reference/entities/account.md).[PrimaryContactId](../reference/entities/account.md#BKMK_PrimaryContactId) lookup column is set. Instead, the simpler service client method or request call is using the [account_primary_contact](../reference/entities/contact.md#BKMK_account_primary_contact) relationship which establishes a many-to-one entity relationship on each related account and a one-to-many entity relationship on the contact.
96
68
97
69
If you examine the properties of the relationship columns, you can see that the `ReferencingEntity` value is `account` and the `ReferencingAttribute` value is `primarycontactid`.
98
70
99
-
100
71
## Use the Disassociate method or DisassociateRequest
101
72
102
73
The <xref:Microsoft.Xrm.Sdk.IOrganizationService>.<xref:Microsoft.Xrm.Sdk.IOrganizationService.Disassociate*> method or the <xref:Microsoft.Xrm.Sdk.Messages.DisassociateRequest> with the <xref:Microsoft.Xrm.Sdk.IOrganizationService>.<xref:Microsoft.Xrm.Sdk.IOrganizationService.Execute*> method are just the reverse of the way that you associate table rows.
103
74
104
-
The following code reverses the associations made in the sample above.
Although there is no particular advantage in doing so, if you wanted to use the <xref:Microsoft.Xrm.Sdk.Messages.DisassociateRequest>, you can replace the last line with this:
75
+
You can view an example `Disassociate` method call in the previously shown code sample. If you wanted to use the <xref:Microsoft.Xrm.Sdk.Messages.DisassociateRequest>, the code would look like this:
Copy file name to clipboardExpand all lines: powerapps-docs/developer/data-platform/org-service/samples/work-activity-party-records.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ contributors:
18
18
This sample code shows how to work with activity party records.
19
19
20
20
> [!div class="nextstepaction"]
21
-
> [SDK for .NET: Work with activity party records sample code](https://github.com/microsoft/PowerApps-Samples/tree/master/dataverse/orgsvc/CSharp/ActivityPartyRecords)
21
+
> [SDK for .NET: Work with activity party records sample code](https://github.com/microsoft/PowerApps-Samples/tree/master/dataverse/orgsvc/CSharp-NETCore/Activities/ActivityParty)
0 commit comments