Jaydata saveChanges() 对跟踪/更改的实体进行计数,但不发送批处理请求(使用 OData v4 提供程序和 Web API)



通过使用jaydata,我将实体添加到具有实体-对象深度嵌套的树结构中。

我将上层实体附加到上下文,并编辑/添加/删除相关的子实体。最后,我使用saveChanges()和一个承诺。

传递给promise的count-value告诉我们所有更改的实体已经被正确计数,但是saveChanges()没有执行批处理请求,持久化这些实体。

所以感觉除了计算实体之外什么都没发生。

我张贴了一个小代码示例。我非常确定,实体的引用设置正确。(使用jaydata, odata v4, web api和angularjs)

是否有人在jaydata中遇到了这个问题并找到了原因?

谢谢你的帮助。=)

问候保罗

// Attach upper entity
DataService.jaydata.attach(viewModel.currentSkillTree.entity);
// Generating new entities
var newSkill = new DataService.jaydata.Skills.elementType({
    Id: undefined,
    Name: 'New skill',
    Levels: [],
    IconId: 47,
    SkillTreeUsage: []
});
var newSkillLevel = new DataService.jaydata.SkillLevels.elementType({
    Id: undefined,
    ShortTitle: 'New level',
    Skill: newSkill,
    SkillId: undefined,
    Level: 1,
    RequirementSets: []
});
var newRequirementSet = new DataService.jaydata.RequirementSets.elementType({
    Id: undefined,
    SkillLevel: newSkillLevel,
    SkillLevelId: undefined,
    SkillTree: undefined,
    SkillTreeId: viewModel.currentSkillTree.entity.Id,
});
var newSkillTreeElement = new DataService.jaydata.SkillTreeElements.elementType({
    Id: undefined,
    SkillTree: undefined,
    SkillTreeId: viewModel.currentSkillTree.entity.Id,
    Skill: newSkill,
    SkillId: undefined,
    Position: { X: x, Y: y }
});
// Completing object-references
viewModel.currentSkillTree.entity.Elements.push(newSkillTreeElement);
newSkill.Levels.push(newSkillLevel);
newSkill.SkillTreeUsage.push(newSkillTreeElement)
newSkillLevel.RequirementSets.push(newRequirementSet);
// Saving
DataService.jaydata.saveChanges()
.then(function (cnt) {
    console.log('Saved entities:', cnt);
    // The cnt-result in console is 4 
    // But no request was executed, nothing was saved 
}, function (exception) {
    console.log(exception); // Also no exception was thrown
});

所以不要那么刻薄。

解决上面的问题给我的解决方案,因为我尝试了几乎每一个组合与实体(添加,附加,.save(), . savechanges(),对象引用等,找出它没有任何意义,它只是以同样的方式,似乎是如此的bug),最终在一个解决方案与经典嵌套异步调用。

解决方案是将实体单独保存在嵌套的承诺中,并关闭jaydata的批处理行为,以避免重复请求。

您可以在$data.defaults

中找到该选项。$data.defaults.OData.disableBatch = true;

作为结果,我现在正在处理好旧的令人讨厌的厄运金字塔,这至少给了可能性,以正确的顺序保存实体,完全控制,api需要它的方式。

      // Saving new SkillLevelRequirement connection
      if (isConnectionGiven === false) {
        // The first level of source skill where the target-skill-requirement will be added
        var sourceSkillLevel = Enumerable
          .From(sourceSkill.Levels)
          .FirstOrDefault(null, function (x) {
            return x.Level === 1;
          });
        // The last level of the target-skill to solve
        var targetSkillLevel = Enumerable
          .From(targetSkill.Levels)
          .FirstOrDefault(null, function (x) {
            return x.Level === targetSkill.Levels.length;
          });
        // First set of first level from source skill (will be used to add skilllevel-requirement)
        var firstRequirementSet = sourceSkillLevel.RequirementSets[0];
        // New RequirementAsignment
        var newRequirementAssignment = new DataService.jaydata.RequirementAssignments.elementType({
          RequirementSetId: firstRequirementSet.Id,
          Order: 1
        });
        // New Requirement
        var newRequirement = new DataService.jaydata.Requirements.elementType({
          Title: requirementTypes.SKILL_CONNECTION,
          RequirementOfIntId: undefined,
          RequirementOfBoolId: undefined,
          RequirementOfSkillLevelId: 0
        });
        // New RequirementOfSkillLevel
        var newRequirementOfSkillLevel = new DataService.jaydata.RequirementsOfSkillLevel.elementType({
          SkillLevelId: targetSkillLevel.Id,
        });
        // Loading symbol
        showBusyIndicator();
        newRequirementOfSkillLevel.save()
        .then(function () {
          newRequirement.RequirementOfSkillLevelId = newRequirementOfSkillLevel.Id;
          newRequirement.save()
          .then(function () {
            newRequirementAssignment.RequirementId = newRequirement.Id;
            newRequirementAssignment.save()
            .then(function () {
              // Loading symbol will be closed after tree reloaded
              reloadCurrentTree();
            }, function (exception) {
              showJayDataExceptionModal(exception);
            });
          }, function (exception) {
            showJayDataExceptionModal(exception);
          });
        }, function (exception) {
          showJayDataExceptionModal(exception);
        });
      }
    }

@jaydata开发者:感谢42根新的白头发。我仍然认为我使用你的工具是错误的,jaydata可以做得更好。认真地说,最好完善你的文档。今天没有甜点。

相关内容

  • 没有找到相关文章

最新更新