This diagram shows the QueryExpression class and related classes. A sample query in C# is also shown.

wiki_queryexpression1.png


QueryExpression usage example

QueryExpression query = new QueryExpression()
{
    Distinct = false,
    EntityName = "contact",
    ColumnSet = new ColumnSet("fullname", "address1_telephone1"),
    LinkEntities =
    {
        new LinkEntity
        {
            JoinOperator = JoinOperator.LeftOuter,
            LinkFromAttributeName = "parentcustomerid",
            LinkFromEntityName = "contact",
            LinkToAttributeName = "accountid",
            LinkToEntityName = "account",
            LinkCriteria =
            {
                Conditions =
                {
                    new ConditionExpression("name", ConditionOperator.Equal, "Litware, Inc.")
                }
            }
        }
    },
    Criteria =
    {
        Filters =
        {
            new FilterExpression
            {
                FilterOperator = LogicalOperator.And,
                Conditions =
                {
                    new ConditionExpression("address1_stateorprovince", ConditionOperator.Equal, "WA"),
                    new ConditionExpression("address1_city", ConditionOperator.In, new String[] {"Redmond", "Bellevue" , "Kirkland", "Seattle"}),
                    new ConditionExpression("createdon", ConditionOperator.LastXDays, 30),
                    new ConditionExpression("emailaddress1", ConditionOperator.NotNull)
                },
            },
            new FilterExpression
            {
                FilterOperator = LogicalOperator.Or,
                Conditions =
                {
                    new ConditionExpression("address1_telephone1", ConditionOperator.Like, "(206)%"),
                    new ConditionExpression("address1_telephone1", ConditionOperator.Like, "(425)%")
                }
            }
        }
    },
    Orders =
    {
        new OrderExpression
        {
            AttributeName = "modifiedon"
        }
    }
};

QueryByAttribute usage example

//  Create query using QueryByAttribute.
QueryByAttribute querybyattribute = new QueryByAttribute("account");
querybyattribute.ColumnSet = new ColumnSet("name", "address1_city", "emailaddress1");
 
//  Attribute to query.
querybyattribute.Attributes.AddRange("address1_city");
 
//  Value of queried attribute to return.
querybyattribute.Values.AddRange("Redmond");
 
//  Query passed to service proxy.
EntityCollection retrieved = _service.RetrieveMultiple(querybyattribute);
 

.