繁体   English   中英

Breeze.js 1.4.1属性未定义不为null

[英]Breeze.js 1.4.1 properties undefined not null

根据Breeze支持的建议,我已升级到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);
  });
}

问题在于,在微风的早期版本中,属性otherProperty和childOne将是具有空值的可观察到的敲除,而属性childrenTwo将是一个可观察的空数组。 但是,正如我在控制台中看到的那样,所有三个属性都未定义? 这是故意的吗?

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

更新1:

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

更新2:

再次感谢Jay Traband,我发现微风的metastore不了解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; }
  }
} 

我只是做了一些简单的测试,无法对此进行复制。 在调用createEntity之后,在所有测试中,我都将实体的导航属性视为可剔除的可观察对象。 一些想法;

您确定您不会无意中

  • 使用backingStore骨干模型库而不是淘汰赛 通过breeze.config.initializeAdapter
  • 对属性应用不同的大小写,即通过使用breeze.NamingConvention

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM