Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Mix early and late bound entities

Mix early and late bound entities

Applies To: CRM 2015 on-prem, CRM Online

In Microsoft Dynamics CRM, 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>() });

See Also

Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.
Show:
© 2015 Microsoft