Domanda

Thanks in advance for taking the time to read my post. Any help would be much appreciated. I feel like I am soooo close!

I have two parent tables "Father" and "Mother". I have a child table "Child" with foreign keys tied to aId and bId, as shown in my model below. I'm using Breeze to query "Father" and extending "Child.Mother". But when I view the results, I get the following error:

*[Q] Unhandled rejection reasons (should be empty): ["TypeError: undefined is not a function...]

I'm assuming it has to do with the way I have my model configured, and Breeze just isn't interpreting it correctly. Here is my model (please excuse the poor pluralization of "child"):

    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; }
            }
        }

And here is my query:

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

Soluzione

Your expand should be 'Childs.Mother', notice the 's'.

I'd like to also suggest that you modify your Child class to be the following for clarity and brevity:

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; }
}

By removing the 's' from Father and Mother, as well as removing the ForeignKey attribute, you're letting EF match the relationships by convention.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top