我确定我做错了什么,但我无法弄清楚。我正在使用 Breezejs Todo + Knockout 示例来重现我的问题。我有以下数据模型:
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 的属性。我的数据模型有问题吗?日志消息是:
Parent property id
Parent property otherProperty
childOne undefined
childTwo undefined