Retrieve related entities of each, using RetrieveMultipleRequest

Answered Retrieve related entities of each, using RetrieveMultipleRequest

  • Tuesday, December 04, 2012 7:41 PM
     
      Has Code

    I'm trying to retrieve a list of entities from CRM, but I'd like to get each one with the related entities. So far, I've the following code:

    FilterExpression filterExpression = new FilterExpression();
    ConditionExpression condition = new ConditionExpression(Constants.ModifiedOnAttribute, ConditionOperator.GreaterEqual, lastSync);
    filterExpression.AddCondition(condition);
    
    QueryExpression query = new QueryExpression()
    {
         EntityName = entityName,
         ColumnSet = new ColumnSet(attributesMetadata.Select(att => att.Name).ToArray<string>()),
         Criteria = filterExpression,
         Distinct = false,
         NoLock = true
    };
    
    RetrieveMultipleRequest multipleRequest = new RetrieveMultipleRequest();
    multipleRequest.Query = queryExpression;
    
    RetrieveMultipleResponse response = (RetrieveMultipleResponse)proxy.Execute(multipleRequest);

    In the variable response, I can see the EntityCollection attribute, but inside, Related entities always come empty.

    I'd like to know if it is possible to retrieve the set of a given entities, with the related entities, using RetrieveMultipleRequest, rather than go one by one using RetrieveRequest.

    TIA!

    Milton

All Replies

  • Tuesday, December 04, 2012 8:39 PM
     
     Answered

    Hi,

    I think you have to use the LinkEntity-Member in the QueryExpression to fill the marked collection: http://msdn.microsoft.com/en-us/library/gg328149.aspx

    Best regards,

    Andreas


    Andreas Buchinger
    Microsoft Dynamics Certified Technology Specialist
    MCPD: SharePoint Developer 2010

  • Wednesday, December 05, 2012 4:58 AM
     
     Proposed Has Code

    Hi Milton ,

    I think this may help you so, By using Link Entity you can able to retrieve the related entity data

    //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)
        {
         //Add your logic to get the Entity Data
        }


    Warm Regards, Suresh Kumar D

    • Proposed As Answer by Suresh Kumar D V Wednesday, December 05, 2012 4:58 AM
    •