Breeze projection query from already-loaded entity -


if use breeze load partial entity:

    var query = entityquery.from('material')         .select('id, materialname, materialtype, materialsubtype')         .orderby(orderby.material);          return manager.executequery(query)             .then(querysucceeded)             .fail(queryfailed);          function querysucceeded(data) {             var list = partialmapper.mapdtostoentities(                 manager, data.results, entitynames.material, 'id');             if (materialsobservable) {                 materialsobservable(list);             }             log('retrieved materials remote data source',                 data, true);         } 

...and want have different partial query same entity (maybe few other fields example) i'm assuming need separate query fields weren't retrieved in first query?

ok, if want use same fields retrieved in first query (id, materialname, materialtype, materialsubtype) want call fields different names in second query (materialname becomes "name", materialtype becomes "mastertype" , on) possible clone partial entity have in memory (assuming in memory?) , rename fields or still need separate query?

i think "union" 2 cases 1 projection if afford so. simplify things dramatically. it's important understand following point:

you not need turn query projection results entities!

backgound: ccjs example

you learned projection-into-entities technique ccjs example in john papa's superb pluralsight course "single page apps jumpstart". ccjs uses technique specific reason: to simplify list update without making trip server.

consider ccjs "sessions list" populated projection query. john didn't have turn query results entities. have bound directly projected results. remember knockout happily binds raw data values. user never edits sessions on list directly. if displayed session values can't change, turning them observable properties waste of cpu.

when tap on session, go session view/edit screen access every property of complete session entity. ccjs needs full entity there looks full (not partial) session in cache and, if not found, loads entity server. point there no particular value in having converted original projection results (partial) session entities.

now edit session - change title - , save it. return "sessions list"

question

how make sure updated title appears in sessions list?

if bound sessions list html projection data objects, objects not entities. they're objects. entity edited in session view not object in collection displayed in sessions list. yes, there corresponding object in list - 1 has same session id. not same object.

choices

#1: refresh list server reissuing projection query. bind directly projection data. note data consist of raw javascript objects, not entities; not in breeze cache.

#2: publish event after saving real session entity; subscribing "sessions list" viewmodel hears event, extracts changes, , updates copy of session in list.

#3: use projection-into-entity technique can use session entity everywhere.

pros , cons

#1 easy implement. requires server trip every time enter sessions list view.

one of ccjs design goals that, once loaded, should able operate entirely offline 0 access server. should work crisply when connectivity intermittent , poor.

ccjs always-ready guide conference. tells instantly sessions available, when , can find session want, you're walking halls, , there. if you've been tech conference or hotel know wifi awful , app useless if works when has direct access server.

#1 not suited intended operating environment ccjs.

the ccjs jumpstart part way down "server independent" path; you'll see closer full offline implementation soon.

you'll lose ability navigate related entities. sessions list displays each session's track, timeslot , room. that's repetitive information found in "lookup" reference entities. you'll either have expand projection include information in "flattened" view of session (fatter payload) or clever on client-side , patch in track, timeslot , room data hand (complexity).

#2 helps offline/intermittent connectivity scenarios. of course you'll have set messaging system, establish protocol saved entities , teach sessions list find , update affected session projection object. that's not super difficult - breeze entitymanager publishes event may sufficient - take more code.

#3 "server independence", has small projection payload, super-easy, , cool demonstration of breeze. have manage ispartial flag know whether session in cache complete. that's not hard.

it more complicated if needed multiple flavors of "partial entity" ... seems going. not issue in ccjs.

john chose #3 ccjs because fit application objectives.

that doesn't make right choice every application. may not right choice for you.

for example, if have fast, low latency connection, #1 may best choice. don't know.

i cast-to-entity approach myself because easy , works of time. think choice before make it.

summary

  1. you not have turn projection query results entities
  2. you can bind projected data directly, without knockout observable properties, if read-only
  3. make sure have reason convert projected data (partial) entities.

ccjs has good reason convert projected query data entities. you?


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -