Use the early bound entity classes to add or update associations between related records
Applies To: CRM 2015 on-prem, CRM Online
In Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online 2015 Update, you can create an association by using early binding in several ways. To create a one-to-many relationship, you can use the AddLink method in the OrganizationServiceContext class. To create a many-to-many relationship, you can use the Associate method in the IOrganizationService class to create an association. You can also create the association by updating the foreign key of the target entity to match the primary key of the new source entity.
For a complete sample showing how to add and remove associations, see Sample: Associate records (early bound).
The following code example shows how to create an association between a contact and an account.
You use the Associate method to create both one-to-many and many-to-many associations. The following code example shows how to create a one-to-many association between an account and a contact.
Relationship relationship2 = new Relationship("account_primary_contact"); EntityReferenceCollection relatedEntities = new EntityReferenceCollection(); relatedEntities.Add(new EntityReference(Account.EntityLogicalName, firstaccount.Id)); _serviceProxy.Associate(Contact.EntityLogicalName, firstcontact.Id, relationship2, relatedEntities);
Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.