Breeze querying local cache with EF and Web API -


problem

i have view 6 drop downs. each of being populated web api call. want use breeze run query locally once has populated remote server

the code runs fine when data call against server. issue when trying query local cache. never results returned. approach flawed or doing wrong ?

server side

view model

class genericdropdown() { public int value{get;set;} public string option{get;set;}  } 

the webapi [a single sample method]

  [httpget]         // api/<controller>         public object getsomevals()         {              return _context.getclinician();           } 

the repository [a single sample method]

public ienumerable<genericdropdown> getdropdownval() {      return context.somemodel(a=>new{a.id,a.firstname,a.lastname}).tolist().                     select(x => new genericdropdown         { value = x.id, option = x.firstname+ " " + x.lastname});}  } 

client side

datacontext.js

   var _manager = new breeze.entitymanager("endpoint");  //being called view model      var getdropdownbindings = function(ko1, ko2) {  //first add entity local metadatastore populate entity          $.when(             adddd('cliniciandropdown', webapimethod),             getdata(ko1, webapimethod, null, 'cliniciandropdown'),              adddd('doctypedropdown', webapimethod);              getdata(ko2, webapimethod, null, 'doctypedropdown'),          ).then(querysucceeded).fail(queryfailed);           function querysucceeded(data) {             logger.log('got drop down vals', "", 'datacontext', true);         }      };   //add entity local store. first param typename , second  resource name (web api method)      var adddd = function(shortname,resname) {          _manager.metadatastore.addentitytype({             shortname: shortname,             namespace: "namespace",             autogeneratedkeytype: breeze.autogeneratedkeytype.identity,             defaultresourcename:resname,             dataproperties: {                 value: { datatype: datatype.int32,                   isnullable: false, ispartofkey: true },                 option: { datatype: datatype.string, isnullable: false }             }         });         return _manager.metadatastore.registerentitytypector(shortname, null, null);      };  //get data      var getdata = function(observablearray, dataendpoint, parameters, mapto) {         if (observablearray != null)             observablearray([]);      //to do: incorporate logic server or local call depending on // whether method accessed first time          var query = breeze.entityquery.from(dataendpoint);         if (mapto != null && mapto != "")             query = query.totype(mapto);          if (parameters != null)             query = query.withparameters(parameters);  //this approach doesnt work on local querying jquery complains  //there no 'then' method. not sure how implement promises  //when querying locally    /*     return _manager.executequery(query).then(querysucceeded).fail(queryfailed);           function querysucceeded(data) {             if (observablearray != null)                 observablearray(data.results);           } */   //the array length query 0  var data = _manager.executequerylocally(query);   observablearray(data.results); return;       };  //generic error handler  function queryfailed(error) {          logger.log(error.message, null, 'datacontext', true);     } 

viewmodel.js

//in durandal's activate method populate observable arrays  datacontext.getdropdownbindings (ko1,ko2); 

viewmodel.html

<select class="dropdown" data-bind="options: ko1, optionstext: 'option', value: 'value', optionscaption: 'clinicians'"></select>  <select class="dropdown" data-bind="options: ko2 optionstext: 'option', value: 'value', optionscaption: 'document types'"></select> 

you can execute local queries against types described metadata.

without more information can't sure, guess getsomevals method not returning 'entities' loose data. in other words, types of objects returned getsomevals method must entities (or contain entities within projection) in order breeze able perform local query. because breeze knows how cache , query entities has no ideas how cache 'arbitrary' query results.

note can return anonymous type containing entities of different types server, (in order populate static small datasets), individual items must 'entities'. in case, breeze take apart anon result , pick out entities include in entitymanager cache.

per question of how perform local query promises, use fetchstrategy.fromlocalcache using method.

i.e. query

 var results = em.executequerylocally(query) 

can expressed as:

 query = query.using(fetchstrategy.fromlocalcache);  return em.executequery(query).then(data) {    var results = data.results;   } 

the local query still executed synchonously made async.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -