0

我有一个复杂的 M:M:M 查​​询,我无法弄清楚。我的案例:我需要从特定培训中检索与学员相关的所有额外费用。
关系如下:

  • 实习生 <-> 培训 M:M
  • 实习生 <-> 额外费用 M:M
  • 培训 <-> 额外费用 1:M

我的代码目前看起来像这样,但我什至不知道这是否是要走的路:

if (context.MessageName == "Update" && context.Stage == 20)
        {
            
            targetEntity = context.InputParameters["Target"] as Entity;
            var courseID = targetEntity.Id;

            QueryExpression Query = new QueryExpression { EntityName = "cref8_extrakost", ColumnSet = new ColumnSet(true) };

            // LINK BETWEEN A TRAINING AND A CURSIST
            LinkEntity TrainingCursist = new LinkEntity
            {
                LinkFromEntityName = "cref8_cursist",
                LinkToEntityName = "cref8_opleiding_cref8_cursist",
                LinkFromAttributeName = "cref8_cursistid",
                LinkToAttributeName = "cref8_cursistid",
                Columns = new ColumnSet(true),
                JoinOperator = JoinOperator.Inner
            };
            TrainingCursist.LinkCriteria.AddCondition("cref8_opleidingid", ConditionOperator.Equal, courseID);

            // LINK BETWEEN A CURSIST AND A EXTRA COST
            LinkEntity ExtraCostCursist = new LinkEntity
            {
                LinkFromEntityName = "cref8_extrakost",
                LinkToEntityName = "cref8_extrakost_cref8_cursist ",
                LinkFromAttributeName = "cref8_extrakost",
                LinkToAttributeName = "cref8_cursistid",
                JoinOperator = JoinOperator.Inner,
                Columns = new ColumnSet(true)
            };
            ExtraCostCursist.LinkCriteria.AddCondition("cref8_cursistid", ConditionOperator.Equal, "34b5de6b - 0758 - ec11 - 8f8f - 000d3aad43bd");

            Query.LinkEntities.Add(TrainingCursist);
            Query.LinkEntities.Add(ExtraCostCursist);

            var collection = service.RetrieveMultiple(Query);
        }

任何帮助将不胜感激

最好的问候,
安东尼

4

0 回答 0