使用PartyList的QueryExpression出错

时间:2015-02-05 19:15:58

标签: c# .net dynamics-crm-2011 dynamics-crm crm

我正在尝试检索其所需的约会"包含在帐户列表中的一个实体上。 requiredattendees有一种PartyList。 我的查询如下:

var query = new QueryExpression("appointment")
{
      ColumnSet = columnSet,
      Criteria = new FilterExpression(LogicalOperator.Or)
};

并添加条件:

GetAccounts()
.Select(a => new ConditionExpression("requiredattendees", ConditionOperator.Contains, a.Id))
.ForEach(c => query.Criteria.AddCondition(c));


a.Id is the account guid.

我收到了以下错误:

Cannot add attribute requiredattendees of type partylist in a condition
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral]]

2 个答案:

答案 0 :(得分:6)

此代码用于服务预约,但如果我没记错,那么预约就是一样的。希望这有帮助

QueryExpression qe = new QueryExpression
{
    EntityName = "serviceappointment",
    Criteria = new FilterExpression
    {
        FilterOperator = LogicalOperator.And,
        Conditions = 
        {
            new ConditionExpression
            {
                AttributeName = "scheduledstart", 
                Operator = ConditionOperator.LessThan,
                Values = 
                {
                    endTime
                }
            },
            new ConditionExpression
            {
                AttributeName = "scheduledend",
                Operator = ConditionOperator.GreaterThan,
                Values =
                {
                    startTime
                }
            }
        }
    },
    LinkEntities = 
    {
        new LinkEntity
        {
            LinkFromEntityName = "activitypointer",
            LinkFromAttributeName = "activityid",
            LinkToEntityName = "activityparty",
            LinkToAttributeName = "activityid",
            LinkCriteria = new FilterExpression
            {
                FilterOperator = LogicalOperator.And,
                Conditions = 
                {
                    new ConditionExpression
                    {
                        AttributeName = "partyid",
                        Operator = ConditionOperator.Equal,
                        Values = 
                        {
                            someEntity.id
                        }
                    }
                }
            }
        }
    }
};

答案 1 :(得分:0)

QueryExpression query = new QueryExpression(LetterEntityAttributeNames.EntityName)
                {
                    ColumnSet = new ColumnSet(new string[]
                        {
                            LetterEntityAttributeNames.SubjectFieldName,
                            LetterEntityAttributeNames.RegardingObjectId,
                            LetterEntityAttributeNames.ToFieldName
                        }),
                    Criteria = new FilterExpression
                    {
                        FilterOperator = LogicalOperator.And,
                        Conditions =
                            {
                                new ConditionExpression
                                {
                                    AttributeName = LetterEntityAttributeNames.DirectChannelTypeFieldName,
                                    Operator = ConditionOperator.Equal,
                                    Values =
                                    {
                                        DirectChannelType
                                    }
                                },
                                new ConditionExpression
                                {
                                    AttributeName = LetterEntityAttributeNames.RegardingObjectId,
                                    Operator = ConditionOperator.Equal,
                                    Values =
                                    {
                                        RegardingId
                                    }
                                }
                            }
                    },
                    LinkEntities =
                        {
                            new LinkEntity
                            {
                                LinkFromEntityName = ActivityPointerEntityAttributeNames.EntityName,
                                LinkFromAttributeName = ActivityPartyAttributeNames.ActivityId,
                                LinkToEntityName = ActivityPartyAttributeNames.EntityName,
                                LinkToAttributeName = CampaignActivityAttributeNames.Id,
                                LinkCriteria = new FilterExpression
                                {
                                    FilterOperator = LogicalOperator.And,
                                    Conditions =
                                    {
                                        new ConditionExpression
                                        {
                                            AttributeName = ActivityPointerAttributeNames.PartyIdField,
                                            Operator = ConditionOperator.Equal,
                                            Values =
                                            {
                                                ToEntityGuid
                                            }
                                        }
                                    }
                                }
                            }
                        }
                };