1

根据 Breeze 支持的建议,我升级到了 1.4.1,但我遇到了以下问题。以前,新创建的实体上的导航属性已定义,但为空值敲除 observables。我修改了 Breezejs TODO 应用程序来展示这一点。

我的数据模型如下,我的前端代码在这里:

function reproduce() {
  breeze.NamingConvention.camelCase.setAsDefault();
  var manager = new breeze.EntityManager(serviceName);
  manager.fetchMetadata().then(function () {
    var parent = manager.createEntity('Parent');
    console.log('otherProperty ' + parent.otherProperty());
    console.log('childOne ' + parent.childOne());
    // I cannot call parent.childrenTwo() since childrenTwois undefined
    console.log('childrenTwo ' + parent.childrenTwo);
  });
}

问题在于,在之前版本的微风中,属性 otherProperty 和 childOne 将是具有空值的可淘汰可观察对象,而属性 childrenTwo 将是空的可观察数组。但是,正如我在控制台中看到的所有三个属性都未定义?这是故意的吗?

我当然可以自己定义它们,但这是很多工作,我希望轻而易举地为我做一些事情。同样根据 Breeze 文档,“很少有理由定义元数据中已经描述的属性。” http://www.breezejs.com/documentation/extending-entities

更新1:

感谢 Jay Traband,在我的复制应用程序中,我没有正确设置大小写。然而 childrenTwo 仍然是未定义的,我相信它应该是一个可观察的数组。我的生产应用程序确实设置了外壳,所以我必须重新调查。

更新 2:

再次感谢 Jay Traband,我发现微风元存储不知道 ChildTwo 类型。因此,我似乎没有以某种方式注册它?我对 Java Hibernate 比对实体框架更熟悉。下面我的数据模型中是否缺少某些内容?

更新3:

ChildTwo 没有明确的外键,我添加了它并且它有效。我想我真的需要记住 Breeze 想要一个明确的外键。

public class ChildTwo
{
  [Key]
  public int Id { get; set; }

  public int ParentId { get; set; }

  [ForeignKey("ParentId")]
  public Parent Parent { get; set; }
}

数据模型。

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Todo.Models
{
  public class Parent
  {
    public Parent()
    {
      ChildrenTwo = new List<ChildTwo>();
    }
    [Key]
    public int Id { get; set; }

    [Required]
    public string OtherProperty { get; set; }

    [Required]
    public ChildOne ChildOne { get; set; }

    [Required]
    public IList<ChildTwo> ChildrenTwo { get; set; }
  }
  public class ChildOne
  {
    [Key]
    [ForeignKey("Parent")]
    public int Id { get; set; }

    public Parent Parent { get; set; }
  }
  public class ChildTwo
  {
    [Key]
    public int Id { get; set; }

    public Parent Parent { get; set; }
  }
} 
4

1 回答 1

1

我只是做了一些简单的测试,无法重现。在调用createEntity后,我在所有测试中都将我的实体的导航属性视为淘汰可观察对象。几个想法;

你确定不是不小心

  • 使用backingStore骨干模型库而不是knockout。通过微风.config.initializeAdapter
  • 将不同的外壳应用于您的属性,即通过使用轻风.NamingConvention
于 2013-08-17T17:20:25.523 回答