Retrive EntityData using QueryExpression Uisng LinkEntities In MS CRM 2011

Retrive EntityData using QueryExpression Uisng LinkEntities In MS CRM 2011

private void RetrieveEntityData()

        {

            try

            {

                QueryExpression query = new QueryExpression()

                {

                    EntityName = <EntityName>,

                    ColumnSet = new ColumnSet()

                    {

                        Columns = new System.Collections.ObjectModel.ObservableCollection<string>()

                    }

                };

                foreach (var item in attributeDetails)

                {

                    query.ColumnSet.Columns.Add(item.SchemaName.ToLower());

                }

                LinkEntity linkentity = new LinkEntity();

                linkentity.LinkFromEntityName = <EntityName>;

                linkentity.LinkToEntityName = relatedEntityName;

                linkentity.LinkFromAttributeName = linkFromAttribute;

         linkentity.LinkToAttributeName = linkToAttribute;

                linkentity.JoinOperator = JoinOperator.Inner;

                linkentity.LinkCriteria = new FilterExpression();

                ConditionExpression condition = new ConditionExpression();

                condition.AttributeName = linkToAttribute;

                condition.Operator = ConditionOperator.Equal;

                condition.Values = new ObservableCollection<object>();

                condition.Values.Add(ReqGuid);

                linkentity.LinkCriteria.Conditions.Add(condition);

                query.LinkEntities = new ObservableCollection<LinkEntity>();

                query.LinkEntities.Add(linkentity);

                // query.PageInfo = new PagingInfo { Count = MaxRecordsToReturn, PageNumber = 1, PagingCookie = null };

                OrganizationRequest request = new OrganizationRequest() { RequestName = “RetrieveMultiple” };

                request[“Query”] = query;

                IOrganizationService service = SilverlightUtility.GetSoapService();

                service.BeginExecute(request, new AsyncCallback(DataGridList_ClickCallback), service);

            }

            catch (SystemException se)

            {

                _syncContext.Send(new SendOrPostCallback(showErrorDetails), se);

            }

        }

Cheers,

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s