我相信我做错了什么,但我无法弄清楚。我正在使用Breezejs Todo + Knockout示例来重现我的问题。我有以下数据模型:Breeze.js实体框架多个一对一的相同类型(父 - >儿童childOne,儿童childTwo)
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Todo.Models
{
public class Parent
{
public Parent()
{
}
[Key]
public int Id { get; set; }
[Required]
public string OtherProperty { get; set; }
public Child ChildOne { get; set; }
public Child ChildTwo { get; set; }
}
public class Child
{
[Key]
public int Id { get; set; }
public int ParentId { get; set; }
[ForeignKey("ParentId")]
public Parent Parent { get; set; }
}
}
在应用程序中我做到以下几点:
breeze.NamingConvention.camelCase.setAsDefault();
var manager = new breeze.EntityManager(serviceName);
manager.fetchMetadata().then(function() {
var parentType = manager.metadataStore.getEntityType('Parent');
ko.utils.arrayForEach(parentType.getPropertyNames(), function (property) {
console.log('Parent property ' + property);
});
var parent = manager.createEntity('Parent');
console.log('childOne ' + parent.childOne);
console.log('childTwo ' + parent.childTwo);
});
的问题是,childOne和childTwo没有定义为父母的性能。 我的数据模型有问题吗?日志消息:
Parent property id
Parent property otherProperty
childOne undefined
childTwo undefined
好的,这是我想的,但我只是想确定,因为这是一个痛苦的解决。 –