2

我需要检查并查看用户是否在特定团队中。我假设我必须从团队开始,但我不太确定。只查看和查看用户所属的所有团队会更容易。有没有人有在插件中使用 N:N 关系的例子?

这是我到目前为止的代码......

// Set the properties of the QueryExpression object.
teamQuery.EntityName = "team";
teamQuery.AddAttributeValue("name", "Team");
teamQuery.ColumnSet = teamColumnSet;

EntityCollection teamDetail = service.RetrieveMultiple(teamQuery);

foreach (var teamDetail in teamDetail.Entities)
{
    teamGuid = teamDetail.Id;
}

感谢您的帮助!!

加里

4

2 回答 2

7

这是我的最终解决方案...

QueryExpression teamQuery = new QueryExpression("team");
ColumnSet teamColumnSet = new ColumnSet("name");

teamQuery.ColumnSet = teamColumnSet;
teamQuery.Criteria = new FilterExpression();
teamQuery.Criteria.FilterOperator = LogicalOperator.And;
teamQuery.Criteria.AddCondition("name", ConditionOperator.Equal, "Sales");
teamQuery.AddLink("teammembership", "teamid", "teamid").AddLink ("systemuser", "systemuserid", "systemuserid").LinkCriteria.AddCondition("systemuserid", ConditionOperator.Equal, salesRepGuid);

 EntityCollection teamDetail = service.RetrieveMultiple(teamQuery);

加里

于 2013-05-02T22:31:01.167 回答
1

您可以使用 fetchXML。这将检查一个服务器请求而不是两个(一个用于获取 teamid,第二个用于检查 N:N 关系)

            string fetchXML = @"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>
  <entity name='systemuser'>
    <filter type='and'>
      <condition attribute='systemuserid' operator='eq' value='{0}' />
    </filter>
    <link-entity name='teammembership' from='systemuserid' to='systemuserid' visible='false' intersect='true'>
      <link-entity name='team' from='teamid' to='teamid' alias='ai'>
        <filter type='and'>
          <condition attribute='name' operator='eq' value='{1}' />
        </filter>
      </link-entity>
    </link-entity>
  </entity>
</fetch> ";

            Guid userID; //assign userid here. 
            string teamName = "team to check";
            fetchXML = string.Format(fetchXML, userID, teamName);

            EntityCollection result = service.RetrieveMultiple(new FetchExpression(fetchXML));

            bool isUserInTeam = result.Entities.Count > 0; 
于 2013-05-01T23:20:12.393 回答