我有一个父子表结构。
我正在尝试删除子记录。这是我的简化视图模型。
MyNameSpace.ParentViewModel = function () {
var self = this;
self.dataSource = upshot.dataSources.GetRecords.refresh();
self.jobs = self.dataSource.getEntities();
self.removeChild1 = function (child) {
$.each(self.jobs(), function() {
this.JobStep.remove(jobStep);
});
};
self.removeChild2 = function (child) {
self.dataSource.deleteEntity(child);
};
};
MyNameSpace.Parent = function (data) {
var self = this;
self.Id = ko.observable(data.Id);
self.SomeProperty = ko.observable(data.SomeProperty);
upshot.addEntityProperties(self, "Parent:#MyNameSpace.Models");
};
MyNameSpace.Child = function (data) {
var self = this;
self.Id = ko.observable(data.Id);
self.ParentId = ko.observable(data.ParentId);
self.Parent = ko.observable(data.Parent ? new MyNameSpace.Parent(data.Parent) : null);
self.SomeChildProperty = ko.observable(data.SomeChildProperty );
upshot.addEntityProperties(self, "Child:#MyNameSpace.Models");
};
当我尝试使用removeChild1删除子记录时,我收到错误:
Use 'deleteEntity' to delete entities from your array. Destructive delete is not yet implemented.
当我尝试使用removeChild2删除子记录时,出现错误:
'Entity not cached in data context. '
显然,在第一个版本中,我引用子记录的ObservableArray集合并从那里删除它。删除了正确的对象,但是非实现错误会导致它失败。
在第二个版本中,我使用了upshot和EF魔法,我不确定会出现什么问题。
有什么想法吗?