0

I'm following John Papa's course on SPA's with Durandal and Breeze and I'm having a problem with the method EntityQuery.fromEntities. Indeed, I'm watching the course mainly as a reference to understand how to use Durandal and Breeze, because I'm coding a totally different SPA.

Indeed, the one I'm coding doesn't has just one Breeze controller, it has one controller per aggregate. So for each controller I have one Breeze's EntityManager. My doubt then is the following: I have one CustomersController, and following John's course to list just the table of customer I've made a projection query and loaded just partial entities.

Now, when I'm going to access the details and editing of each customer, I need the full data. So, I've used the following code in my viewmodel:

function reloadCustomer(customer) {
    return EntityQuery.fromEntities(customer)
    .using(customersManager).execute()
    .then(querySucceeded);
}

The only problem is that this query is aimed with resourceName Customers. This is a problem, because since the customersManager has serviceName /api/customers the request is being made to /api/customers/Customers which doesn't exists.

How can I use the EntityQuery.fromEntities method when I have this scenario of multiple controllers, instead of a single /api/breeze service url?

1 Answer 1

1

You need to check the Breeze.js docs on their site to learn more about building queries. The method you are using assumes you have matched an entity type ('Customer') to a resource ('Customers') and that your data service is always going to hit the same controller. You have many options on how to set it up but the easiest is to define a dataservice for your manager to define a data service your manager will use and then you can map the entity to the resource, as you see in this tutorial, or you can use .from() instead of fromEntities()

Define a data service

var ds = new breeze.DataService({
    serviceName: '/api'
});
var mgr = new breeze.EntityManager({ dataService: ds });

and then you can use .from() -

var query = EntityQuery.from('myControllerName/customers')
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer @PWKad, this solves me even another problem: with this I can get rid of the multiple managers. But now I have a problem to fetch metadata. Using this approach, the manager looks for metadata at /api/metadata while it should look at /api/breeze/metadata. I didn't find on the docs how to customize where to look for metadata. How can I approach this? Thanks again for the aid.
One approach that I have seen before is to use a 'parent' manager that contains all of the metadata and links the child managers together - I believe that the Breeze.js site has a good working example of this in the TempHire sample - breezejs.com/samples/temphire-sample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.