Retrieve Multiple
The RetrieveMultiple web service method is used to retrieve multiple objects of a specific entity using a search criteria.
There are two approaches to specify the search criteria:
- QueryByProperty
- QueryExpression
QueryByProperty
This is the simpler of the two retrieval approaches and retrieves instances of a specific entity type by specifying a set of property and value pairs.
When a Property is another Corrigo Entity (refer to the Properties section of the Entities page) then specific properties of that entity (referred to as child entity) is listed as Entity.PropertyName.
PropertySet
Example: Retrieve a list of Specialties that return the properties DisplayAs (Speciality Name) and TaxCode (Tax Code). TaxCode is another Corrigo Entity with its own set of properties and is thus retrieved using the TaxCode's DisplayAs property in the form TaxCode.DisplayAs.
var results = corrigoService.RetrieveMultiple(new QueryByProperty
{
/* Set Entity Type */
EntityType = EntityType.Specialty,
/* Define Property Set */
PropertySet = new PropertySet {Properties = new[] {"DisplayAs", "TaxCode.DisplayAs" }},
/* Return 10 objects max */
Count = 10
}
);
PropertyValuePair
Example: Retrieve all Emergency Work Orders
QueryByProperty queryByProperty = new QueryByProperty();
/* Set Entity Type */
queryByProperty.EntityType = EntityType.WorkOrder;
/* Retrieve all properties */
queryByProperty.PropertySet = new AllProperties();
/* Specify property for child entity */
List<PropertyValuePair> conditions = new List<PropertyValuePair>();
conditions.Add(new PropertyValuePair() {PropertyName = "Priority.DisplayAs", Value = "Emergency"});
queryByProperty.Conditions = conditions.ToArray();
/* Return 10 objects max */
queryByProperty.Count = 10;
/* Perform search */
var results = corrigoService.RetrieveMultiple(queryByProperty);
QueryExpression
The QueryExpression class is used to retrieve objects of a specific entity by specifying complex query criteria.
The approach is similar to a SQL query and uses the properties in the Entity's PropertySet to define the elements that are populated in resultset.
The FilterExpression class is used to filter the results of the query by specifying complex conditions and logical filter expressions.
Class | Description | Values |
---|---|---|
Criteria | Specify complex conditions and logical filter expressions to filter the results of the query. | |
Distinct | Specify whether the results of the query return unique entity instances in the result set. Synonymous with the Distinct keyword in a SQL query. | |
FilterExpression | Specify complex condition expressions (ConditionExpression, ConditionOperator) and logical operators (FilterOperator) to filter the results of the query. Synonymous with the Where clause in a SQL query. | |
Conditions | The condition expression specifies a property, expected value(s) and the relational operator. | |
ConditionExpression | Specifies a conditional expression used to filter the results of a query. | |
ConditionOperator | Specifies the possible values for the operator in a ConditionExpression. | Between NotBetween Equal NotEqual GreaterOrEqual GreaterThan In NotIn LessOrEqual LessThan Like NotLike Null NotNull |
Filters | Specify complex hierarchical filters. | |
FilterOperator | Specifies the possible values for a logical operator in a FilterExpression. | And Or |
Orders | Sets the order in which the entity instances are returned from the query. Uses the OrderExpression class to specify the PropertyName and OrderType. Synonymous with the Order By clause in a SQL query. | Ascending Descending |
Count | Sets the maximum number of results to be returned. Synonymous with the Top keyword in a SQL query. | |
FirstResultIndex | Manage paging to specify the index of the first entity returned, particularly for big result sets (>100 records). |
Example: Retrieve all Work Orders based on scheduled start date and on site by date.
var results = corrigoService.RetrieveMultiple(
new QueryExpression
{
EntityType = EntityType.WorkOrder,
PropertySet = new AllProperties(),
Criteria = new FilterExpression()
{
FilterOperator = LogicalOperator.And,
Conditions = new[]
{
/* Work Order scheduled start date >= some date
And Work Order on site date < some date */
new ConditionExpression()
{
PropertyName = "DtScheduledStart",
Values = new object[]
{
new DateTime(year1, month1, day1)
},
Operator = ConditionOperator.GreaterOrEqual
},
new ConditionExpression()
{
PropertyName = "DtOnSiteBy",
Values = new object[]
{
new DateTime(year2, month2, day2)
},
Operator = ConditionOperator.LessThan
}
}
},
/* Sort result set by Work Order Id */
Orders = new[]
{
new OrderExpression
{
OrderType = OrderType.Descending,
PropertyName = "Id"
}
},
/* Return 100 objects max */
Count = 100
};
);
Updated almost 6 years ago