如何为以下查询编写查询表达式?

发布于 2024-12-23 11:35:56 字数 2568 浏览 1 评论 0原文

我正在尝试在dynamics 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;

I am trying to write a plugin in dynamics crm 4.0. following is my fetch query which working fine. I tested on fetchxml Builder. but when I am trying to convert into QueryExpression it is not returing any result.

<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>  

I am trying to write following code but it is always return 0 records

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲喜皆因你 2024-12-30 11:35:56

使用 new AllColumns() 尝试一下,看看是否有效。我似乎记得一个令人沮丧的问题,如果指定的列不包含数据,则不会返回任何记录。

Try it with new AllColumns() and see if that works. I seem to remember a frustrating issue where if the columns specified do not contain data then no records are returned.

为你拒绝所有暧昧 2024-12-30 11:35:56

请尝试以下操作并在末尾添加您的检索请求代码。

    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",
            }
        }
    };

Try the following and add your retrieve request code at the end.

    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",
            }
        }
    };
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文