I'm new in CRM workflow step development by C#. I need to know what is the main difference between RetrieveRequest and Retrieve in IOrganizationService.
When must use which one?
And is there any example to show how use this objects to run in a performer manner?
In most cases the Retrieve method suffices.
The RetrieveRequest however adds an interesting feature: it provides the option to query data associated with the retrieved object in one go.
Imagine you need invoice data along with its Invoice Product records. One option would be to create a QueryExpression and join the results of the invoice entity and the invoicedetail entity. This would result in one, potentially large table.
With the RetrieveRequest you can query records associated with the retrieved entity in one request.
An example:
private readonly IOrganizationService _service;
public Entity GetFullInvoice(Guid invoiceId)
{
var request = new RetrieveRequest
{
ColumnSet = new ColumnSet(allColumns: true),
Target = new EntityReference("invoice", invoiceId),
RelatedEntitiesQuery = new RelationshipQueryCollection()
};
var relation = new Relationship("invoice_details");
relation.PrimaryEntityRole = EntityRole.Referenced;
var invoiceDetailQuery = new QueryExpression("invoicedetail");
invoiceDetailQuery.ColumnSet = new ColumnSet(allColumns: true);
invoiceDetailQuery.Criteria.AddCondition("invoiceid", ConditionOperator.Equal, invoiceId);
var result = (RetrieveResponse)_service.Execute(request);
return result.Entity;
}
The Entity object returned by GetFullInvoice has a RelatedEntities property holding the entity collections related to the invoice.
Multiple queries can be added to the RetrieveRequest, so it would also be possible to retrieve associated activities etc. in one go as well.
A RetrieveRequest and the Retrieve method of IOrganizationService do exactly the same thing: retrieve a specific record.
Eventually RetrieveRequest can be batched (using the ExecuteMultipleRequest message) but personally I never see a RetrieveRequest batched, because normally UpdateRequest or DeleteRequest are the one batched in order to improve performance.
来源:https://stackoverflow.com/questions/33327565/what-is-the-differences-between-retrieverequest-and-iorganizationservice-retriev