Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You use fetchEntityById as a convenient way to get the specific entity either from cache or from the remote service. Then the expansion must be done in another query. You will almost always want to do it in two steps anyway because you will want to check if the cached version is all you need before going remote and expanding. That check is not included in the code below, but you would just replace <code>return refreshProject(p);</code> with <code>return p.isPartial() ? refreshProject(p) : projectObservable(p);</code> so you only refresh if the entity has been marked as a partial entity or one that needs refreshing for some other reason. You must, of course, implement the logic to mark entities as partial.</p> <pre><code>var getProjectById = function (projectId, projectObservable) { // fetchEntityByKey will look in local cache first (because 3rd // parm is true) and if not there then it will go remote return manager.fetchEntityByKey( 'Project', projectId, true) .then(fetchSucceeded) .fail(queryFailed); // Refresh the entity from remote store function fetchSucceeded(data) { var p = data.entity; return refreshProject(p); } function refreshProject(project) { // fromEntities(someEntity) creates a query that gets only someEntity // from the remote service. return EntityQuery.fromEntities(project) .expand('navigationProp1.complexProp1,' + 'navigationProp1.complexProp2,' + 'navigationProp2.complexProp1,' + 'navigationProp2.complexProp2') .using(manager).execute() .then(querySucceeded) .fail(queryFailed); } function querySucceeded(data) { var p = data.results[0]; return projectObservable(p); } }; </code></pre> <p>The <code>expand</code> clause is quite interesting because you might have a navigation property such as contracts, which is a list of all contracts for a project. If a contract contains only primitive data types you can just expand with <code>.expand('contracts')</code> but if the contract type has one or more complex properties such as a supplier (including various supplier details) then expanding just for contracts will only bring in the Id of the supplier. The syntax is interesting because there is no such property as <code>contracts.supplier</code>, but you tell Breeze to include all the properties of the supplier on each contract with <code>expand('contracts.supplier')</code>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload