QueryExpression Phonecall to Contact

时间:2016-09-30 13:32:24

标签: dynamics-crm-2011

我已经坚持了一下。这是我尝试做的范围:

检索电话录音记录,同时在"至"中引入联系信息。领域。

经过大量研究后,我将代码归结为下面的代码。我不太确定我是否正确地执行链接实体 - 但是无法确定如何进行嵌套连接,因为我需要以某种方式进入activitypointer - > activityparty - >联系......我只是不知道我哪里出错了。任何帮助将不胜感激。

using Microsoft.Crm.Sdk.Messages.Samples;
using Microsoft.Xrm.Sdk.Query.Samples;

QueryExpression qExpression = new QueryExpression("phonecall")
{
    ColumnSet = cs,
    LinkEntities = 
    {

        new LinkEntity()
        {
            EntityAlias = "ap",
            LinkFromEntityName= "phonecall",
            LinkFromAttributeName = "activityid",
            LinkToEntityName = "activitypointer",
            LinkToAttributeName = "activityid",
            JoinOperator = JoinOperator.Inner
        },
        new LinkEntity()
        {
            EntityAlias = "app",
            LinkFromEntityName= "activitypointer",
            LinkFromAttributeName = "activityid",
            LinkToEntityName = "activityparty",
            LinkToAttributeName = "activityid",
            JoinOperator = JoinOperator.Inner,
            LinkCriteria = new FilterExpression
             {
                 Conditions = 
                 {
                     new ConditionExpression("ParticipationTypeMask", ConditionOperator.Equal, 2),                          
                 }
             }
        },
        new LinkEntity()
        {
            EntityAlias = "con",
            Columns = new ColumnSet("fullname","contactid"),
            JoinOperator = JoinOperator.Inner,
            LinkFromEntityName = "activityparty",
            LinkFromAttributeName = "partyid",
            LinkToEntityName = "contact",
            LinkToAttributeName = "contactid"
        }
    }
};

2 个答案:

答案 0 :(得分:0)

看起来我回答了我自己的问题,给了一些灵感。我不得不将链接嵌入链接中。

这就是现在有效的

QueryExpression qExpression = new QueryExpression("phonecall")
        {
            ColumnSet = cs,
            LinkEntities = 
            {                   
                new LinkEntity()
                {
                    EntityAlias = "app",
                    LinkFromEntityName= "phonecall",
                    LinkFromAttributeName = "activityid",
                    LinkToEntityName = "activityparty",
                    LinkToAttributeName = "activityid",
                    JoinOperator = JoinOperator.Inner,
                    LinkCriteria = new FilterExpression
                     {
                         Conditions = 
                         {
                             new ConditionExpression("participationtypemask", ConditionOperator.Equal, 2),                          
                         }
                     },
                     LinkEntities = 
                     {                             
                        new LinkEntity()
                        {
                            EntityAlias = "con",
                            Columns = new ColumnSet("fullname","contactid"),
                            JoinOperator = JoinOperator.Inner,
                            LinkFromEntityName = "activityparty",
                            LinkFromAttributeName = "partyid",
                            LinkToEntityName = "contact",
                            LinkToAttributeName = "contactid"
                        }
                     }
                },
            }
        };

答案 1 :(得分:0)

使用DLaB.Xrm,您可以像这样重写:

var qe = QueryExpressionFactory.Create(cs, "phonecall");
var activityParty = qe.AddLink("activityparty", "activityid");
activityParty.WhereEqual("participationtypemask", 2);
activityParty.AddLink("contact", "partyid", "contactid")
             .AddColumns("fullname","contactid");

要查看更少的代码,往往会让Grok恕我直言更容易。

这就是我将如何阅读列出的5行教学行:

  1. 我正在对电话呼叫实体进行查询
  2. 在活动ID上加入活动方(两者的密钥相同,无需复制)
  3. 其中activityParty的ParticipationTypeMask == 2
  4. 从此加入ActivityParty上的联系人.PartyId == Contact.ContactId
  5. 包括联系人的姓名和身份证明。