Month: October 2015

How to check if two records are related N:N

Posted on

QueryExpression query = new QueryExpression(relationshipName)
     {
         NoLock = true,
         ColumnSet = new ColumnSet(false),
         Criteria =
         {
             Filters =
             {
                 new FilterExpression
                 {
                     FilterOperator = LogicalOperator.And,
                     Conditions =
                     {
                         new ConditionExpression("accountid", ConditionOperator.Equal, accountID.ToString()),
                         new ConditionExpression("contactid", ConditionOperator.Equal, contactId.ToString()),
                     },
                 },
             }
         }
     };
     var result = service.RetrieveMultiple(query);
There is a catch here, if you have created a self referential N:N relationship then the primary fields are “<fieldname>one” and “<fieldname>two”, so incidentidone and incidentidtwo
Advertisements