Take the 2-minute tour ×

I've had some success managing to connect breeze to our custom types on the server by creating a custom metadata definition and adding it to the breeze entity manager.

However, I'm unable to request an object (Employee) that has been custom-defined in javascript and retrieve its relationship(s) completely.

In other words, I have an object called Employee that has a property called "LoginStats" that is a List type on the server. When requesting this object using Breeze only one element returns in the collection, when there should be 6.

The results of the $promise look like this:

data.results[0].loginStats()[0] //object
data.results[0].loginStats()[1] //undefined

Strangely, if I individually select the properties, such as .select("LoginStats") it comes back complete with the 6 items in an array.

How is it possible for me to retrieve this object without spelling out all of the desired properties using a breeze call? I've attempted to use the .expand() clause, but unfortunately we are not connected to EntityFramework in a way that makes this work.

Thanks in advance!

EDIT: Here's a sample of what it looks like when I use the "select" statement vs just requesting the object. These images also demonstrate what happens when I select all of the properties, which is that they are all filled in correctly, but they are no longer observables. Eeeek!

Controller code:

        public IQueryable<Employee> Get(string id)
            var criterion = new Criterion<Employee, bool>(e => e.CustomerId == id);
            var loginStatisticsExtendedProperty = new FillEmployeeLoginStatistics(_UserRoleProvider, _CustomerLoginStatsViewModelRepository);
            var availableCompaniesForEmployess = new AvailableCompaniesForEmployess(_CompanyAffiliatesRepository);
            return _EmployeeRepository.Find(criterion, loginStatisticsExtendedProperty, _EmployeeDetailsExtendedProperty, availableCompaniesForEmployess);
share|improve this question
add comment

1 Answer

Without seeing what the server side controller method(s) that you are calling it's difficult to tell for sure. But I have couple of suggestions.

First make sure that your controller method returns an IQueryable collection. This is only required if you want to use client side queries to further restrict the resource. You can typically make any collection an IQueryable by simply adding an .AsQueryable() call before you return the collection.

Second, the "expand" syntax will only operate against EF backed IQueryables. But you can still return graphs of objects from the client providing that they 'serialize' along with the parent. For "no db" type resources this usually means that you force resolution on the server of any navigation properties that you want sent down to the client. If you add a JsonResultsAdapter you can actually 'debug' into what is being serialized down to the client by breakpointing inside of the 'visitNode' method.

Please post your controller method def's if this is insufficient.

share|improve this answer
Thanks Jay. I've updated the photo album (imgur.com/a/13158) to show my controller. It's the black background pic. I've got it returned as an IQueryable, but do the collections associated with them need to be queryables? They are currently lists. –  letsgetsilly Mar 28 '13 at 20:30
The collections associated with them do not need to be queryable, but you do need to make sure, in your case, that these collections are serialized along with the parent. Take a look at the json payload coming from the server and see if the collections are going over the wire. It's also worth checking that the 'entities' in these collections have a json $type property that maps to one of your client side entity types ( this is assuming you are using the BreezeController attribute). –  Jay Traband Mar 28 '13 at 20:33
The JSON is correct. I see these collections displayed when requesting the URL directly. I added an image to the gallery to illustrate. –  letsgetsilly Mar 28 '13 at 20:38
Anytime you see that the results of a query are not 'observable', this is your clue that you are not serializing entities. (The other clue is that none of the returned 'items' will have an entityType property. In your case this is because you are using a 'select' statement. The select statement causes a projection against your IQueryable into an anonymous .NET type which is then serialized to the client. The client cannot find a match for this type and thus does not bother wrapping it. This will not occur if you get rid of the 'select' statement and return 'strong' types directly. –  Jay Traband Mar 28 '13 at 20:49
The JSON looks correct to me. I see the $type properties coming through the JSON response, and they correlate with my metadata definitions. What else would prevent my child property collections from coming through? Ever heard of just one item in a collection being returned as it is in my case? –  letsgetsilly Mar 28 '13 at 20:53
show 4 more comments

Your Answer


