共用方式為


混合早期與晚期繫結實體

 

發行︰ 2017年1月

適用於: Dynamics 365 (online)、Dynamics 365 (on-premises)、Dynamics CRM 2016、Dynamics CRM Online

在 Microsoft Dynamics 365,您可以混合早期與晚期繫結方法,與強類型和 Entity 類別一起使用。 此方法使用強類型程式碼產生的檔案的兩個靜態中繼資料,以及 Entity 類別及其 Helper 方法的彈性。

下列範例顯示一種混合早期與晚期繫結方法的用法。

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





指派早期繫結執行個體給晚期繫結執行個體

下列範例顯示如何指派早期繫結執行個體給晚期繫結執行個體。

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

© 2017 Microsoft. 著作權所有,並保留一切權利。 著作權