Created
February 14, 2012 22:14
-
-
Save kdeenanauth/1830979 to your computer and use it in GitHub Desktop.
Querying Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Retrieve all accounts owned by the user with read access rights to the accounts and | |
// where the last name of the user is not Cannon. | |
string fetch2 = @" | |
<fetch mapping='logical'> | |
<entity name='account'> | |
<attribute name='accountid'/> | |
<attribute name='name'/> | |
<link-entity name='systemuser' to='owninguser'> | |
<filter type='and'> | |
<condition attribute='lastname' operator='ne' value='Cannon' /> | |
</filter> | |
</link-entity> | |
</entity> | |
</fetch>"; | |
EntityCollection result = _serviceProxy.RetrieveMultiple(new FetchExpression(fetch2)); | |
foreach (var c in result.Entities) | |
{ | |
System.Console.WriteLine(c.Attributes["name"]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Create a query expression specifying the link entity alias and the columns of the link entity that you want to return | |
QueryExpression qe = new QueryExpression(); | |
qe.EntityName = "account"; | |
qe.ColumnSet = new ColumnSet(); | |
qe.ColumnSet.Columns.Add("name"); | |
qe.LinkEntities.Add(new LinkEntity("account", "contact", "primarycontactid", "contactid", JoinOperator.Inner)); | |
qe.LinkEntities[0].Columns.AddColumns("firstname", "lastname"); | |
qe.LinkEntities[0].EntityAlias = "primarycontact"; | |
EntityCollection ec = _orgService.RetrieveMultiple(qe); | |
Console.WriteLine("Retrieved {0} entities", ec.Entities.Count); | |
foreach (Entity act in ec.Entities) | |
{ | |
Console.WriteLine("account name:" + act["name"]); | |
Console.WriteLine("primary contact first name:" + act["primarycontact.firstname"]); | |
Console.WriteLine("primary contact last name:" + act["primarycontact.lastname"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment