Skip to content

Instantly share code, notes, and snippets.

@ashramsey
Created September 5, 2013 03:42
Show Gist options
  • Save ashramsey/6445826 to your computer and use it in GitHub Desktop.
Save ashramsey/6445826 to your computer and use it in GitHub Desktop.
Creates a connection to the CRM, and retrieves all account records (Organisations) from the CRM. I'm guessing, one of the columns is no longer valid??
public List<Entity> GetOrganizations()
{
List<Entity> accounts = null;
// Establish a connection to the organization web service using CrmConnection.
Microsoft.Xrm.Client.CrmConnection connection = CrmConnection.Parse(this.ConnectionString);
using (_orgService = new OrganizationService(connection))
{
// Retrieve the several attributes from the new account.
QueryExpression query = new QueryExpression();
query.EntityName = "account";
query.ColumnSet = new ColumnSet(true);
query.LinkEntities.Add(new LinkEntity("account", "contact", "primarycontactid", "contactid", JoinOperator.LeftOuter));
query.LinkEntities[0].Columns.AddColumns("firstname", "lastname");
query.LinkEntities[0].EntityAlias = "primarycontact";
accounts = _orgService.RetrieveMultiple(query).Entities.ToList();
}
return accounts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment