您需要使用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