Mix early and late bound entities

 

Updated: November 29, 2016

Applies To: Dynamics 365 (online), Dynamics 365 (on-premises), Dynamics CRM 2016, Dynamics CRM Online

In Microsoft Dynamics 365, you can mix early binding and late binding methods to work with both strong types and the Entity class. This approach uses both static metadata from a code-generated file of strong types with the flexibility of the Entity class and its helper methods.

The following example shows one way to mix early and late binding methods.

// Create an organization service context object
AWCServiceContext context = new AWCServiceContext(_serviceProxy);

// Instantiate an account object using the Entity class.
Entity testaccount = new Entity("account");

// Set several attributes. For account, only the name is required. 
testaccount["name"] = "Fourth Coffee";
testaccount["emailaddress1"] = "marshd@contoso.com";

// Save the entity using the organization service context object.
context.AddToAccountSet(testaccount);
context.SaveChanges();







The following sample shows how to assign an early bound instance to a late bound instance.

Entity incident = ((Entity)context.InputParameters[ParameterName.Target]).ToEntity<Incident>();
Task relatedEntity = new Task() { Id = this.TaskId };

incident.RelatedEntities[new Relationship("Incident_Tasks")] = 
new EntityCollection(new Entity[] { relatedEntity.ToEntity<Entity>() });

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright

Community Additions

ADD
Show: