Peristiwa
Kejohanan Dunia Power BI DataViz
14 Feb, 4 PTG - 31 Mac, 4 PTG
Dengan 4 peluang untuk menyertai, anda boleh memenangi pakej persidangan dan berjaya ke Grand Finale LIVE di Las Vegas
Ketahui lebih lanjutPelayar ini tidak lagi disokong.
Naik taraf kepada Microsoft Edge untuk memanfaatkan ciri, kemas kini keselamatan dan sokongan teknikal yang terkini.
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 EntityReference to set the value of a lookup column on the related row.
The simplest way to disassociate two rows in a one-to-many relationship is to set the value of the lookup column to null
.
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.
The main value in using the IOrganizationService.Associate method or the AssociateRequest with the IOrganizationService.Execute method is that you can:
To associate table rows with these APIs you need three things:
Whether the relationship is a one-to-many or many-to-many relationship doesn't matter. The parameters or properties are equivalent.
You can discover the names of the relationships by viewing the customization UI or in the metadata using the Metadata Browser.
More information:
The following example creates a relationship and associates a primary entity with a collection of related entities.
/// <summary>
/// Associate a primary entity with one or more other entities,
/// then remove the association.
/// </summary>
/// <param name="service">Authenticated web service connection.</param>
/// <param name="primaryEntity">Primary entity for the association.</param>
/// <param name="relationship">Type of relationship between the entities.</param>
/// <param name="relatedEntities">Related entities to associate with the primary entity.</param>
/// <returns>True if successful; otherwise false.</returns>
static public bool AssociateDisassociate(IOrganizationService service,
EntityReference primaryEntity, string relationship,
EntityReferenceCollection relatedEntities
)
{
// Define the type of relationship between the entities.
var relation = new Relationship(relationship);
try
{
// Associate the primary entity with the related entities.
service.Associate(primaryEntity.LogicalName, primaryEntity.Id,
relation, relatedEntities);
Console.WriteLine(
$"AssociateDisassociate(): The entities have been associated.");
// Disassociate the primary entity with the related entities.
service.Disassociate(primaryEntity.LogicalName, primaryEntity.Id,
relation, relatedEntities);
Console.WriteLine(
$"AssociateDisassociate(): The entities have been disassociated.");
return true;
}
catch (Exception ex)
{
Console.WriteLine(
$"AssociateDisassociate(): {ex.Message}");
return false;
}
}
Complete code sample: AssociateDisassociate
If you wanted to use the 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.
AssociateRequest request = new AssociateRequest()
{
RelatedEntities = relatedEntities,
Relationship = relation,
Target = primaryEntity
};
service.Execute(request);
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.PrimaryContactId lookup column is set. Instead, the simpler service client method or request call is using the 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.
If you examine the properties of the relationship columns, you can see that the ReferencingEntity
value is account
and the ReferencingAttribute
value is primarycontactid
.
The IOrganizationService.Disassociate method or the DisassociateRequest with the IOrganizationService.Execute method are just the reverse of the way that you associate table rows.
You can view an example Disassociate
method call in the previously shown code sample. If you wanted to use the DisassociateRequest, the code would look like this:
DisassociateRequest request = new DisassociateRequest()
{
RelatedEntities = relatedEntities,
Relationship = relation,
Target = primaryEntity
};
service.Execute(request);
Create table rows using the SDK for .NET
Retrieve a table row using the SDK for .NET
Update and delete table rows using the SDK for .NET
Peristiwa
Kejohanan Dunia Power BI DataViz
14 Feb, 4 PTG - 31 Mac, 4 PTG
Dengan 4 peluang untuk menyertai, anda boleh memenangi pakej persidangan dan berjaya ke Grand Finale LIVE di Las Vegas
Ketahui lebih lanjutLatihan
Modul
Create a relationship between tables in Microsoft Dataverse - Training
Do you need to create relationships between tables? This module will show how and why you can separate data into tables and how to relate between tables to build complex and robust business solutions. It will also explain the different kinds of relationships that you can define between tables in Dataverse.
Pensijilan
Microsoft Certified: Power Platform Developer Associate - Certifications
Demonstrate how to simplify, automate, and transform business tasks and processes using Microsoft Power Platform Developer.
Dokumentasi
Retrieve a table row using the SDK for .NET (Microsoft Dataverse) - Power Apps
Describes options available when retrieving a row programmatically.
Include filtering attributes with plug-in registration - Power Apps
If no filtering attributes are set for a plug-in registration step, then the plug-in executes every time an update message occurs for that event.