Skip to content

Commit 73edf24

Browse files
committed
Moved some CE examples to CDS
1 parent 7ac409c commit 73edf24

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

powerapps-docs/developer/common-data-service/org-service/early-bound-programming.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,26 @@ Which style you choose to use is up to you. The following table provides the adv
136136

137137
Because all the generated classes inherit from the <xref:Microsoft.Xrm.Sdk.Entity> class used with late-bound programming, you can work with entities, attributes, and relationships not defined within classes.
138138

139-
### Example
139+
### Examples
140+
141+
The following example shows one way to mix early and late binding methods using <xref:Microsoft.Xrm.Sdk.Client.OrganizationServiceContext>.
142+
143+
```csharp
144+
// Create an organization service context object
145+
AWCServiceContext context = new AWCServiceContext(_serviceProxy);
146+
147+
// Instantiate an account object using the Entity class.
148+
Entity testaccount = new Entity("account");
149+
150+
// Set several attributes. For account, only the name is required.
151+
testaccount["name"] = "Fourth Coffee";
152+
testaccount["emailaddress1"] = "[email protected]";
153+
154+
// Save the entity using the organization service context object.
155+
context.AddToAccountSet(testaccount);
156+
context.SaveChanges();
157+
158+
```
140159

141160
If a custom attribute was not included in the generated classes, you can still use it.
142161

@@ -154,6 +173,17 @@ var account = new Account();
154173
Guid accountid = svc.Create(account);
155174
```
156175

176+
#### Assign an early bound instance to a late bound instance
177+
The following sample shows how to assign an early bound instance to a late bound instance.
178+
179+
```csharp
180+
Entity incident = ((Entity)context.InputParameters[ParameterName.Target]).ToEntity<Incident>();
181+
Task relatedEntity = new Task() { Id = this.TaskId };
182+
183+
incident.RelatedEntities[new Relationship("Incident_Tasks")] =
184+
new EntityCollection(new Entity[] { relatedEntity.ToEntity<Entity>() });
185+
```
186+
157187
### See also
158188

159189
[Entity Operations using the Organization service](entity-operations.md)<br />

powerapps-docs/developer/common-data-service/org-service/organizationservicecontext.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,17 @@ if (pam != null)
8585
Task firstTask = pam.Contact_Tasks.FirstOrDefault();
8686
}
8787
```
88+
### Use the AddLink method
89+
You can use the <xref:Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.AddLink(Microsoft.Xrm.Sdk.Entity,Microsoft.Xrm.Sdk.Relationship,Microsoft.Xrm.Sdk.Entity)> method to create associations. You must call the <xref:Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges> method before the server is updated with the new link information.
8890

91+
The following code example shows how to create an association between a contact and an account.
92+
93+
```csharp
94+
Relationship relationship = new Relationship("account_primary_contact");
95+
context.AddLink(contact, relationship, account);
96+
context.SaveChanges();
97+
```
98+
8999
<a name="save_changes"></a>
90100

91101
## Save changes

0 commit comments

Comments
 (0)