What is the differences between RetrieveRequest and IOrganizationService.Retrieve in CRM?

痞子三分冷 提交于 2019-12-07 19:16:16

问题


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?


回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!