1

我在 .NET 中定义了以下模型:

 Public Class Request
  <Key()>
  Public Property RequestId As String
  Public Property Description As String
  Public Property InfoCards As List(Of InfoCard)
End Class

Public Class InfoCard
  <Key()>
  Public Property InfocardId As String
  Public Property Description As String
  Public Property RequestId As String
End Class

InfoCard 上的ReqeuestId属性使 EF Code First 可以生成数据库。然后我使用UpshotContext帮助器生成 JavaScript 模型,如下所示:

Html.UpshotContext(bufferChanges:= true) _
  .DataSource(Of UpshotTest.UpshotTest.RequestController)(Function(x) x.GetRequests()) _
  .ClientMapping(Of UpshotTest.Models.Request)("Request") _
  .ClientMapping(Of UpshotTest.Models.InfoCard)("InfoCard")

这很好地生成了所有模型,当我调用refresh结果数据源时,数据按预期检索。

我面临的问题Request.InfoCards(0).Description是当我尝试修改子对象(eq )的属性时。更改该值将触发 中的更改InfoCard,但不会触发Request实体中的更改。因此,调用Request.IsUpdated()将返回false,而调用Request.InfoCards(0).IsUpdated()将返回true

upshot 不知道如何跟踪子实体的变化吗?还是客户端的映射有问题?到目前为止,我已经尝试了几种映射:

  • 手动映射所有属性:

    window.Request = function (initialData) {
        var self = this;
        self.RequestId = ko.observable(initialData.RequestId);
        self.Description = ko.observable(initialData.Description);
        self.InfoCards = ko.observableArray(ko.utils.arrayMap(initialData.InfoCards, function (data) {
           return new window.InfoCard(data);
        }));
    
        upshot.addEntityProperties(self, "Request:#UpshotTest.Models");
    };
    
  • 使用upshot.map

    window.Request = function (initialData) {
        var self = this;
        upshot.map(initialData, upshot.type(Request), self);
    };
    
  • 定义我自己的地图函数并将其传递给结果:

    window.Request = function (initialData) {
        var self = this;
        upshot.observability.configuration.map(initialData, upshot.type(Request), map, self);
    };
    

所有方法的映射似乎都是正确的,除了父实体不知道在其子实体中所做的修改。儿童跟踪甚至可能吗?

4

1 回答 1

4

好的,我最后找到了问题。事实证明,当存在 3 个嵌套实体的层次结构时(即Request -> InfoCard -> InfoField ),此行为是可重现的。修改 InfoField 的值并未反映在父实体中。

经过几个小时的结果调试,我发现罪魁祸首是upshot.js_addTrackingRecursive中的方法。替换调用以解决嵌套更改跟踪问题。obs.track(obj, this._getTracker(), this._entityType);obs.track(obj, this._getTracker(), type);

于 2012-07-09T12:27:09.187 回答