I started leaving a bunch of comments and decided to make it an answer instead. You can always do this to reduce the code needed and improve re-usability -
var thisQuery = breeze.entityQuery.from('Whatever').where('pwkad', '==', 'awesome');
queryRunner(thisQuery);
function queryRunner(query) {
query.execute().fail(queryFailed);
};
function queryFailed(error) {
console.log(error.message);
};
Which has a single defined queryFailed method shared when using the 'queryRunner'. Then you could put all of your reusable code that is agnostic of the type in there. To go a step further you could also build a base query that all other queries 'inherit' (I use that loosely) to where you use parameters to build out the queries and then only maintain a single code base. I highly recommend doing this (I use it in all of my Breeze.js production apps) as it forces you to follow conventions on both the front-end and API code. I won't give away my secret sauce of exactly how this looks for me but here is a quick example -
// All is pseudo code
function getEntityById (manager, type, resourcePath, forceRemote, idProp, idValue, params) {
if (!manager) { throw "Must pass in a manager"; }
var query = breeze.entityQuery.from(resourcePath).toType(type);
if (!forceRemote) {
// Put your code here to get from cache
var entity = breeze.fetchEntityByKey();
if (entity) {
return entity;
}
}
if (params) {
// Pass in a valid params object and set it to whatever
query.withParameters(params);
}
if (idValue && idProp) {
query.where(idProp, '==', idValue);
}
query.execute().fail(queryFailed);
function queryFailed(error) {
console.log(error);
}
}
Which could be called from anywhere that needs to 'get' an entity by Id -
var manager = new breeze.entityManager();
var hamburger = getEntityById(manager, 'Hamburger', 'Hamburgers', true, 'id', 1);
Using this method you can write one single breeze query and call it from anywhere saving tons of time and debugging provided you give the parameters correctly.