Как написать QueryExpression для следующего запроса? - PullRequest
1 голос
/ 29 декабря 2011

Пытаюсь написать плагин в динамике crm 4.0.ниже мой запрос на выборку, который работает нормально.Я тестировал на fetchxml Builder.но когда я пытаюсь преобразовать в QueryExpression, он не получает никакого результата.

<fetch mapping='logical'>
    <entity name='new_involvedperson'>
        <attribute name='new_ageattimeofincident'/>
        <filter type='and'>
            <condition attribute='new_personid' operator='eq' alias='new_InvolvedPersonID' value='{70B1E0F8-9205-E111-9C76-005056A44AF5}'/>
            <condition attribute='new_roletype' operator='eq' value='1'/>
        </filter>
        <link-entity name='new_person' from='new_personid' to='new_personnameid'>
            <attribute name='new_firstname'/>
            <attribute name='new_lastname'/>  
            <attribute name='new_dateofbirth'/>
        </link-entity>
    </entity>
</fetch>  

Я пытаюсь написать следующий код, но он всегда возвращает 0 записей

ColumnSet cols = new ColumnSet();

// Set the properties of the column set.
cols.Attributes.Add("new_ageattimeofincident");

// Create the condition expression.
ConditionExpression condition = new ConditionExpression();
condition.AttributeName = "new_personid";
condition.Operator = ConditionOperator.Equal;
condition.Values = new object[1];
condition.Values[0] = incidentId;

//ConditionExpression condition1 = new ConditionExpression();
//condition1.AttributeName = "new_roletype";
//condition1.Operator = ConditionOperator.Equal;
//condition1.Values = new object[1];
//condition1.Values[0] = roleType;


// Build the filter based on the condition.
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.Conditions.Add(condition);
//filter.Conditions.Add(condition1);

// Create a LinkEntity to link the owner's information to the account.
LinkEntity link = new LinkEntity();
link.LinkCriteria = filter;
link.LinkToEntityName = "new_person";
link.LinkToAttributeName = "new_personid";
link.LinkFromEntityName = "new_involvedperson";
link.LinkFromAttributeName = "new_personnameid";

// Create the query.
QueryExpression query = new QueryExpression();
query.EntityName = "new_involvedperson";
query.ColumnSet = cols;
query.LinkEntities.Add( link);

// Create the request object.
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;

// Execute the request.
RetrieveMultipleResponse retrieved2 = (RetrieveMultipleResponse)service.Execute(retrieve);

return retrieved2.BusinessEntityCollection.BusinessEntities;

Ответы [ 2 ]

0 голосов
/ 05 декабря 2018

Попробуйте выполнить следующее и добавьте код запроса на получение в конце.

    QueryExpression query = new QueryExpression
    {
        EntityName = "new_involvedperson",
        //columns to be included in query
        ColumnSet = new ColumnSet(true),
        Criteria = new FilterExpression(LogicalOperator.And)
        {
            Conditions =
            {
                new ConditionExpression("new_personid", ConditionOperator.Equal, "{70B1E0F8-9205-E111-9C76-005056A44AF5}"),
                new ConditionExpression("new_roletype", ConditionOperator.Equal, 1),
            }
        },
        LinkEntities =
        {
            new LinkEntity()
            {
                LinkFromAttributeName = "new_personid",
                LinkToEntityName = "new_person",
                LinkToAttributeName = "new_personnameid",
            }
        }
    };
0 голосов
/ 29 декабря 2011

Попробуйте это с новой AllColumns () и посмотрите, работает ли это. Кажется, я помню неприятную проблему, когда, если указанные столбцы не содержат данных, никакие записи не возвращаются.

...