我相信我做錯了什麼,但我無法弄清楚。我正在使用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
好的,這是我想的,但我只是想確定,因爲這是一個痛苦的解決。 –