retrieve columns from LinkedEntities in Microsoft CRM 2011

Hi,

You prepare QueryExpression and add some LinkedEntities then you want to retrieve fields from linked part.Just follow the sample;


 QueryExpression query = new QueryExpression()
                    {
                                        ...
                                        ...
                    };

                    FilterExpression filterTicket = new FilterExpression();
                    ...
                    query.Criteria = filterTicket;

                    //all about ticket
                    query.LinkEntities.Add(new LinkEntity("contact", "new_new_ticket_contact", "contactid", "contactid", JoinOperator.Inner));


                    query.LinkEntities[0].EntityAlias = "contacttoticket";
add alias to reach the fields
                    query.LinkEntities[0].Columns.AddColumn("new_ticketid");
add column names to the same level of LinkedEntity to obtain later...


                    query.LinkEntities[0].AddLink("new_ticket", "new_ticketid", "new_ticketid", JoinOperator.Inner);
                    query.LinkEntities[0].LinkEntities[0].EntityAlias = "contacttotickecttonew_customtable";
                    query.LinkEntities[0].LinkEntities[0].Columns.AddColumn("new_tourid");
                    query.LinkEntities[0].LinkEntities[0].AddLink("new_customtable", "new_customtable", "new_customtableid", JoinOperator.Inner);
                    ...

                    ...

You can get Linked Entities field(s) via Attributes from the response object  after execute the query against CRM Service Proxy.
AliasedValue is type of the returning object and has a value parameter which may be EntityReference or Entity, based upon joined object.


 if (ent.Attributes.Contains("contacttotickecttonew_customtable"))
                        {
                          string str =  ((EntityReference) ((AliasedValue) ent.Attributes["contacttotickecttonew_customtable"]).Value).Id
                        }


regards,

Comments

Popular posts from this blog

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in CrmServiceHelper.cv

Exception caught instantiating TERADATA report server extension SQL Reporting Services

you face "ISV code aborted the operation" when you change status of the any record in Dynamics CRM 2013