您需要使用appointment
和systemuser
之间的关系实体activitypointer
。正如你在我的例子中看到的那样,这会让事情变得复杂一些。
至少有2种可能的方式来建立你所需的查询:
var qe = new QueryExpression
{
EntityName = "appointment",
ColumnSet = new ColumnSet("subject"),
LinkEntities =
{
new LinkEntity
{
EntityAlias = "ap",
JoinOperator = JoinOperator.Inner,
Columns = new ColumnSet(false),
LinkFromEntityName = "appointment",
LinkFromAttributeName = "activityid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "activityid",
LinkCriteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("partyid", ConditionOperator.Equal, userid),
},
},
},
},
};
2)您可以通过查询systemuser:
1)正如你已经想通,您可以通过systemuserid筛选约会systemuserid并添加任命为链接的实体(如在一个SQL查询JOIN):
var qe2 = new QueryExpression
{
EntityName = "systemuser",
ColumnSet = new ColumnSet(false),
LinkEntities =
{
new LinkEntity
{
EntityAlias = "ap",
Columns = new ColumnSet(false),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "systemuser",
LinkFromAttributeName = "systemuserid",
LinkToEntityName = "activityparty",
LinkToAttributeName = "partyid",
LinkEntities =
{
new LinkEntity
{
EntityAlias = "a",
Columns = new ColumnSet("subject"),
JoinOperator = JoinOperator.Inner,
LinkFromEntityName = "activityparty",
LinkFromAttributeName = "activityid",
LinkToEntityName = "appointment",
LinkToAttributeName = "activityid",
},
},
},
},
Criteria = new FilterExpression
{
Conditions =
{
new ConditionExpression("systemuserid", ConditionOperator.Equal, userid),
},
},
};
,关于对参与角色的过滤器,你就必须在participationtypemask
添加一个条件在activitypointer
:
// user is Organizer, Owner, required or optional Attendee
ConditionExpression("participationtypemask", ConditionOperator.In, new int[] { 5, 6, 7, 9 }),
非常感谢您的回答,这样可以节省我的一天。还有一件事,如果在ColumnSet中设置了“组织者”,它将检索包含所有字段的EntityCollection。是否可以在组织者中指定我想要的字段? – bidou88
当然这是可能的 - 而不是像我的expample中那样只指定*“subject”*,你可以简单地设置'new ColumnSet(true)'来检索所有的字段。如果您需要根据条件构建QueryExpression,请将其分开并根据需要设置属性。我倾向于以所示的方式构造QueryExpression,因为它使它们更像SQL查询的可读性。 – Filburt
谢谢,我没有说好我的问题。如果在我的ColumnSet中添加组织者,它将检索组织者,但所有字段都附加到组织者。我想要做的只是在组织者中只有特定的领域。我不知道是否清楚? – bidou88