0

I'm facing a problem with breeze metadata. I developed a system with breeze controller. I see my model in the metadata including all navigation properties. When I fetch the data from the server I see my objects filled with the expected field, but the deserialized object on client side only includes the simple field without the collection.

I see in the metadata and the returned object from the server like following:

 public partial class DesignType
    {      
        public DesignType()
        {        
            this.Product = new HashSet<Product>();
        }

        public int Id { get; set; }       
        public string Name { get; set; } 
        public string Code { get; set; }        

        public virtual ICollection<Product> Product { get; set; }
        public virtual VisionType Vision { get; set; }        
    }

public partial class VisionType
    {   

        public VisionType()
        {    

            this.DesignType = new HashSet<DesignType>();
        }

        public int Id { get; set; } 
        public string Name { get; set; } 

        public virtual ICollection<DesignType> DesignType { get; set; }
    }

Here is the query code :

var query = breeze.EntityQuery.from("Designs");
            breeze.manager.executeQuery(query).then(function (queryResult) {
                callback(queryResult.results)
            }).fail(function (queryFailed) {
                error(queryFailed);
            });

The results objects only contain the simple data properties and ignors the properties ICollection Product and Vision .

Any ideas. Thanks in advance...

Wasim
  • 1,915
  • 5
  • 24
  • 39
  • Can you please post query, method in controller and C# model of Object A? Possibly definition of Object Y and B as well (at least important parts with ID and foreign key). – Dominictus Dec 10 '13 at 08:12

1 Answers1

1

Your query only asks for the root type, DesignType, so that is all that should be returned. I'll assume that your server side method is not returning the related Product and Vision entities (which it could do but I'm betting that you're not making that happen).

So Breeze is doing what you asked.

If the client wants the related entities, it can ask for them with an expand clause:

breeze.EntityQuery.from("Designs")
      .expand('Products, Vision')

Check out the documentation on queries and expand

Update 11 Dec 2013

If I understand your comment, (a) you now understand why you don't see Product because you are neither requesting products on the client nor pushing them out from the server, (b) your web api is including the related Vision instance and (b) you are seeing Vision data in the JSON response from the query.

The remaining mystery is why someDesignType.Vision is returning null.

Please read "Query response debugging" focusing in particular on the reference navigation property and the foreign key property on Product that points back to the DesignType. If you're still mystified, please show us how the details of the Vision navigation property as explained there.

Community
  • 1
  • 1
Ward
  • 17,793
  • 4
  • 37
  • 53
  • My server side query is : (DbQuery)Context.Include("VisionType"); So at least I was supposed to see the Vision entity. I read this question about (referentialConstraint) , so please your feedback : http://stackoverflow.com/questions/17158159/breeze-returns-navigation-properties-in-the-metadata-but-not-on-the-entities – Wasim Dec 11 '13 at 09:44
  • Thanks for the update , I updated my question with the two entities , lets ignore product away right now , I think its similar problem. As you can see nothing special , I walked by the book as your documentation . Please let me know if you need any other inputs to figure out the problem. – Wasim Dec 12 '13 at 08:01
  • BTW , I read in the Query response debuggin : Did you define foreign key (FK) properties? Developers often neglect to define or identify the FK properties. Breeze requires FK properties to implement navigation properties. In some cases you can define navigation properties without FKs but Breeze will not be able to maintain those properties in cache. How I can do that in EF5 , in the code without doing this in the designer ? Thaks ... – Wasim Dec 12 '13 at 08:09
  • EF training is out of scope for a Breeze question. You might want to learn from Julie Lerman who knows her stuff. Start with "[Code First Relationships Fluent API](http://msdn.microsoft.com/en-us/data/hh134698.aspx)". – Ward Dec 14 '13 at 05:44
  • Ok , thanks . At least I know the problem related to FK. This quite sad , so I have to do this for all the entites , I hope breeze can do it without like Ria services with silverlight . – Wasim Dec 14 '13 at 09:15