0

我在预验证插件上有一条删除消息。在插件中,我尝试从要删除的记录(extraKost)中检索所有相关记录(cursists)(用于计算目的)。通常,当我查询这些相关实体时,我应该返回 2 个实体(cursists)。我得到 0 返回,所以我认为数据库在插件代码完成工作之前删除了记录。这很奇怪,因为在“预验证”中,插件代码应该在数据库操作发生之前完成。我知道这个记录有 2 个相关记录,所以这不是问题。下面是插件的完整代码。

if (context.MessageName == "Delete" && context.Stage == 10)
        {
            var extraKostEntity = context.PreEntityImages.FirstOrDefault(q => q.Key == "cref8_extrakost").Value;
            EntityReference extraKostERef = ((EntityReference)extraKostEntity.Attributes["cref8_extrakosttraining"]);
            Guid trainingID = new Guid(extraKostERef.Id.ToString());
            double extraKost = Convert.ToDouble(extraKostEntity.Attributes.FirstOrDefault(q => q.Key == "cref8_prijs").Value);

            var training = service.Retrieve("cref8_opleiding", trainingID, new ColumnSet(true));

            var query = new QueryExpression("cref8_cursist");
            query.ColumnSet = new ColumnSet(true);
            var intersection = new LinkEntity
            {
                LinkFromEntityName = "cref8_cursist",
                LinkToEntityName = "cref8_extrakost_cref8_cursist",
                LinkFromAttributeName = "cref8_cursistid",
                LinkToAttributeName = "cref8_cursistid",
                JoinOperator = JoinOperator.Inner
            };
            intersection.LinkCriteria.AddCondition("cref8_extrakostid", ConditionOperator.Equal, extraKostEntity.Id);
            query.LinkEntities.Add(intersection);

            var cursistCollection = service.RetrieveMultiple(query);

            //Loop through the result
            foreach (var cursist in cursistCollection.Entities)
            {
                //YEARLY BUDGET CURSIST DATA 
                ConditionExpression ceYearlyBudgetFromTrainee = new ConditionExpression("cref8_cursist", ConditionOperator.Equal, cursist.Id);
                ConditionExpression ceYearlyBudgetYear = new ConditionExpression("cref8_jaar", ConditionOperator.Equal, training.Attributes.FirstOrDefault(q => q.Key == "cref8_jaarstartopleiding").Value);

                FilterExpression filter = new FilterExpression();
                filter.Conditions.Add(ceYearlyBudgetFromTrainee);
                filter.Conditions.Add(ceYearlyBudgetYear);

                QueryExpression qeYearlyBudget = new QueryExpression("cref8_jaarlijkbudget");
                qeYearlyBudget.ColumnSet = new ColumnSet(true);
                qeYearlyBudget.Criteria.AddFilter(filter);
                EntityCollection yearlyBudgetResult = service.RetrieveMultiple(qeYearlyBudget);

                //BUDGETTEN 
                double budgetOver = Convert.ToDouble(yearlyBudgetResult.Entities.First().Attributes.FirstOrDefault(q => q.Key == "cref8_overigebudget").Value);
                //CALCULATIES
                double nieuwBudget = budgetOver + extraKost;

                Entity budget = new Entity("cref8_jaarlijkbudget");
                budget["cref8_jaarlijkbudgetid"] = yearlyBudgetResult.Entities.First().Attributes.FirstOrDefault(q => q.Key == "cref8_jaarlijkbudgetid").Value;
                budget["cref8_overigebudget"] = nieuwBudget;
                service.Update(budget);
            }
        }



所有信息

  • 删除消息
  • 预验证插件
  • 同步
  • 这是组装的唯一步骤
  • 该步骤有一个工作正常的 Pre Image

任何帮助将不胜感激。我不知道是什么原因造成的。

此致,

安东尼

4

0 回答 0