breeze .extend方法,两个父表共享同一个子

时间:2014-04-29 18:01:18

标签: javascript model breeze

提前感谢您花时间阅读我的帖子。任何帮助将非常感激。我觉得我太近了!

我有两个父表“父亲”和“母亲”。我有一个子表“Child”,外键绑定到aId和bId,如下面的模型所示。我正在使用Breeze查询“父亲”并扩展“Child.Mother”。但是当我查看结果时,我收到以下错误:

* [问]未处理的拒绝原因(应为空): [“TypeError:undefined不是函数...]

我假设它与我配置模型的方式有关,而Breeze只是没有正确解释它。这是我的模型(请原谅“孩子”的可怜的多元化):

    public class Models
        {
            public class Father
            {
                // Primary key
                public int FatherId { get; set; }
                ...

                // Navigation property
                public ICollection<Child> Childs { get; set; }
            }

            public class Mother
            {
                // Primary key
                public int MotherId { get; set; }
                ...

                // Navigation property
                public ICollection<Child> Childs { get; set; }
            }

            public class Child
            {
                // Primary key
                public int ChildId { get; set; }

                // Foreign key
                public int FatherId { get; set; }
                public int MotherId { get; set; }
                ...

                // Navigation property
                [ForeignKey("FatherId")]
                public Father Fathers{ get; set; }

                [ForeignKey("MotherId")]
                public Mother Mothers { get; set; }
            }
        }

这是我的疑问:

            function getFatherMotherChild(o) {
                var query = EntityQuery
                    .from('Father')
                    .expand('Child.Mother')

1 个答案:

答案 0 :(得分:0)

您的展开应该是&#39; Childs.Mother&#39;,请注意&#39;。

我还建议您为了清晰和简洁而将您的Child类修改为以下内容:

public class Child
{
   // Primary key
   public int ChildId { get; set; }

   // Foreign key
   public int FatherId { get; set; }
   public int MotherId { get; set; }
   ...

   // Navigation property
   public Father Father{ get; set; }
   public Mother Mother { get; set; }
}

删除&#39;从父亲和母亲,以及删除ForeignKey属性,你让EF按惯例匹配关系。