Kopīgot, izmantojot


Mix early and late bound entities

 

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();





Assign an early bound instance to a late bound instance

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

Use the early bound entity classes in code
Use the late bound entity class in code
Sample: Use the organization service context

Microsoft Dynamics 365

© 2016 Microsoft. All rights reserved. Copyright