Javascript Breeze.js 1.4.1未定义的属性不为空

Javascript Breeze.js 1.4.1未定义的属性不为空,javascript,knockout.js,breeze,Javascript,Knockout.js,Breeze,根据Breeze support的建议,我升级到了1.4.1,但我有以下问题。以前,新创建的实体上的导航属性已定义,但值为空的敲除观测值。我修改了Breezejs TODO应用程序来显示这一点 我的数据模型如下,前端代码如下: function reproduce() { breeze.NamingConvention.camelCase.setAsDefault(); var manager = new breeze.EntityManager(serviceName); mana

根据Breeze support的建议,我升级到了1.4.1,但我有以下问题。以前,新创建的实体上的导航属性已定义,但值为空的敲除观测值。我修改了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);
  });
}
问题在于,在以前版本的breeze中,otherProperty和childOne属性将是一个空值的敲除可观测值,而childrenTwo属性将是一个空的可观测数组。但是,正如我在控制台中看到的,所有三个属性都未定义?这是故意的吗

我当然可以自己定义它们,但这是一项艰巨的工作,我希望breeze能为我做些什么。同样根据Breeze文档,“很少有理由定义元数据中已经描述的属性。”

更新1:

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

更新2:

再次感谢Jay Traband,我发现breeze metastore不知道ChildTwo类型。因此,我似乎没有以某种方式注册它?与实体框架相比,我更熟悉JavaHibernate。我下面的数据模型中缺少什么

更新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; }
  }
} 
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.ComponentModel.DataAnnotations.Schema;
命名空间Todo.Models
{
公共类父类
{
公共家长()
{
ChildrenTwo=新列表();
}
[关键]
公共int Id{get;set;}
[必需]
公共字符串OtherProperty{get;set;}
[必需]
公共ChildOne ChildOne{get;set;}
[必需]
公共IList ChildrenTwo{get;set;}
}
公务舱ChildOne
{
[关键]
[外键(“母公司”)]
公共int Id{get;set;}
公共父级{get;set;}
}
公共二等儿童
{
[关键]
公共int Id{get;set;}
公共父级{get;set;}
}
} 

我只是做了一些简单的测试,无法重新编程。调用createEntity后,我在所有测试中将实体的导航属性视为淘汰观察值。一些想法

你确定你不是无意的吗

  • 使用备份存储主干模型库而不是淘汰。通过breeze.config.initializedapter
  • 将不同的外壳应用于您的属性,即通过使用breeze.NamingConvention
我只是做了一些简单的测试,无法重新编程。调用createEntity后,我在所有测试中将实体的导航属性视为淘汰观察值。一些想法

你确定你不是无意的吗

  • 使用备份存储主干模型库而不是淘汰。通过breeze.config.initializedapter
  • 将不同的外壳应用于您的属性,即通过使用breeze.NamingConvention
这可能是一个复制粘贴错误,但您意识到,如果这些属性是可观察的,您需要正确使用这些属性吗?ie-console.log('otherProperty'+parent().otherProperty());如果要获取属性,请选择parent()。如果要查看该属性是否未定义,请选择otherProperty?由于这些属性未定义,因此像函数一样调用它们会导致错误。日志调用只是为了告诉我它们是未定义的还是实际可见的。我添加了一条注释,说明了我无法()调用属性的原因。使用parent()调用它们。otherProperty不应返回错误。。。还可以考虑把你之前提出的问题中的答案作为帮助别人在将来找到它们的答案。错误如预期的“未捕获类型错误:对象不是函数”。我标记了我回答的其他问题。这可能是一个复制粘贴错误,但您意识到,如果这些属性是可观察的,您需要正确使用parans吗?ie-console.log('otherProperty'+parent().otherProperty());如果要获取属性,请选择parent()。如果要查看该属性是否未定义,请选择otherProperty?由于这些属性未定义,因此像函数一样调用它们会导致错误。日志调用只是为了告诉我它们是未定义的还是实际可见的。我添加了一条注释,说明了我无法()调用属性的原因。使用parent()调用它们。otherProperty不应返回错误。。。还可以考虑把你之前提出的问题中的答案作为帮助别人在将来找到它们的答案。错误如预期的“未捕获类型错误:对象不是函数”。我标记了其他问题的答案。我的复制应用程序中的大小写属性不正确。otherProperty和childOne属性现在已正确定义。但是,childrenTwo仍然没有定义,根据我的模型,我觉得它应该是一个空的可观察数组?使用MetadataStore.getEntityType方法查看Breeze认为“父”类型的元数据属性是什么。我猜您不会看到“ChildTwo”导航属性。如果是这样,那么很可能您没有为Entity Framework正确配置服务器端,因为此元数据是从EF DbContext检索的。您是对的,先生!getPropertyNames()不返回ChildrenTwo。抱歉,我是.NET(java guy)的新手,我在DBContext中添加了一个ChildTwo的数据库集,但它仍然不适合