Downloading Breeze Navigation Properties for Offline Use

I am currently utilizing the most recent versions of Angular, breeze, and EF.

Within the client environment, I am working on creating a sophisticated object named Quote that is associated with a job. This Quote includes a QuoteMeasure, which in turn contains a navigation property called measure:

var quote = em.createEntity("Quote", { id: breeze.core.getUuid() }),
quoteMeasure,
measure;
measure = _getMeasureFromLookups(4);
quoteMeasure = em.createEntity("QuoteMeasure", { id: breeze.core.getUuid(), quoteId: quote.id });

I have attempted the following approach which triggers a query to the server:

quoteMeasure.measureId = measure.id;
quoteMeasure.entityAspect.loadNavigationProperty("measure").then(function () {
    console.log(quoteMeasure.measure);
});
quote.quoteMeasures.push(quoteMeasure);
job.quotes.push(quote);

directed to the URL /Breeze/Data/Measure?$filter=Id%20eq%204&

This URL, however, does not exist. I am interested in manually setting the navigation property as it pertains to static data that was previously obtained through a breeze query on the server:

    [HttpGet]
    public object Lookups()
    {
        var measures = UnitOfWork.MeasureRepository.Get(null, q => q.OrderBy(m => m.Ordinal)).ToList();
        return new { measures = measures };
    }

The function _getMeasureFromLookups is designed to retrieve the previously stored measure. I would prefer to assign it in this manner:

quoteMeasure.measure = measure;

However, I am encountering a cryptic error on the client:

Error: A is undefined M@//llhst/X/Scripts/breeze.min.js:1 d/f.set@//llhst/X/Scripts/breeze.min.js:5 _createNewQuote@//llhst/X/Scripts/app/services/jobService.js:76

This issue appears to be related to downloading a complete tree of objects via the lookup, rather than focusing on an individual measure entity. The Breeze documentation discusses 'Omitting navigation properties' here, but fails to provide clear instructions on how to implement this.

Therefore, my query is centered around the best practices for loading navigation property data offline. How can the above code sample be adjusted to function correctly?

Answer №1

To meet your requirements appropriately, you can create the quote and quoteMeasure entities in the following manner:

var quote = em.createEntity("Quote", { id: breeze.core.getUuid() });

//The assignment quoteId: quote.id is equivalent to quote.quoteMeasures.push(quoteMeasure)
//No need to add it again to the collection
var quoteMeasure = em.createEntity("QuoteMeasure", { id: breeze.core.getUuid(), quoteId: quote.id });

var measure = _getMeasureFromLookups(4);

quoteMeasure.measure = measure;

//or
//quoteMeasure.measureId = measure.id

//Your _getMeasureFromLookups function should resemble this
function _getMeasureFromLookups(measureId) {
  //getEntityByKey will fetch Measure from the client cache
  return em.getEntityByKey('Measure', measureId);
}

Invoking loadNavigationProperty will trigger a query to the server.

The section on 'Omitting navigation properties' explains how you can exclude the principal side of the association. For instance, in your EF model, if you do not want a Quote to navigate to all QuoteMeasures, you can do the following:

//EF Model on Server
public class Quote {

  //Simply remove or comment out this collection navigation property
  //public virtual ICollection<QuoteMeasure> QuoteMeasures { get; set; }
}

I hope this clarifies things for you.

Answer №2

It appears that the issue stemmed from forgetting to include the following lines:

        Configuration.ProxyCreationEnabled = false;
        Configuration.LazyLoadingEnabled = false;

The absence of these lines resulted in all navigation properties and their related properties being preloaded, leading to the elusive error mentioned earlier. No further changes were necessary to resolve the problem and the code now functions correctly.

Answer №3

EntityAspect.loadNavigationProperty()
will always trigger a server request. To prevent multiple requests and load properties without separate calls, opt for Eager loading in EF.

If you encounter null properties upon Breeze fetch and wish to avoid multiple loadNavigationProperty calls, consider utilizing the EntityQuery.expand() method. This allows you to specify which properties to load

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve JSON data by making an AJAX request to a PHP file using the POST method

I am looking to extract data from a form using an AJAX call. The information is received in PHP as a string that looks like: 'fname':'abc','lname':'xyz','email':'','pass':'',& ...

Challenges with loading times in extensive AngularJS applications

We are currently tackling performance issues related to the loading time of our AngularJS application. The page takes a significant amount of time to load, and we are exploring potential causes for this delay. One factor that could be contributing to the ...

I'm curious why I can only see the HTML code and not the three.js code as well

I attempted to run a sample three.js game today, but only the HTML code appeared. I've also installed three.js with npm and tried running it with the VSC Live Server, but it's not working. You can find the source code here. What should be my nex ...

Ensure that the heading cells in the table header (thead) are properly

Struggling with aligning the thead with the td in the tbody? I attempted adjusting the thead using display: table-header-group;, but discovered that padding doesn't work on 'table-header-group'. This led me to try adding padding-left to my t ...

Steps to Utilize Google Apps Script from a Website

I've been on a mission to find the solution to my problem. I have a basic web page with HTML/CSS/JS. What I want is for users to visit the page and immediately have it call up a Google script I created, which will pull information from a spreadsheet a ...

Is it possible to simultaneously send a JSON object and render a template using NodeJS and AngularJS?

I'm currently facing issues with my API setup using NodeJS, ExpressJS Routing, and AngularJS. My goal is to render a template (ejs) while also sending a JSON object simultaneously. In the index.js file within my routes folder, I have the following s ...

Velocity.js causing a slowdown in animated performance

Currently, I am attempting to animate spans, and while the animation is functional, it appears to be somewhat choppy and lacks smoothness. https://codepen.io/pokepim/pen/JBRoay My assumption is that this is due to my use of left/right for animation purpos ...

Is it possible to make changes to dynamically inserted HTML using jQuery.ajax?

I'm facing a scenario in jQuery where I make an ajax call that inserts HTML into my website. However, I also need to perform operations on this inserted HTML within the same ajax call's success callback function. Here is a simplified version of ...

I can't seem to figure out what's causing this error to pop up in my coding setup (Tailwind + Next.js). It

I've been struggling with this problem for a week now and despite my efforts, I haven't been able to find a solution yet. However, I have made some progress in narrowing down the issue. The problem arises when I try to execute the yarn build comm ...

Updating row values in an Angular table

I have a reusable table with the [cellData]="row" attribute to populate each cell on the table (see sample table in the screenshot). My question is, how can we replace the null values on the template with "---" so that instead of displ ...

Shifting the placement of a component in Vue JS when hovering the mouse

I am facing an issue regarding the positioning of components. I have four images, and when you hover over them, a specific component is displayed as shown below: https://i.sstatic.net/gybcy.png For example, hovering over a yellow image will display a dif ...

What could be causing me to receive a 401 error when making a Rails jQuery POST request?

I am currently utilizing devise within a rails application. I have successfully logged into my rails server (devise) using the following curl command: curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST h ...

Edit the contents within HTML strings without altering the HTML structure

If I have a string of HTML, it might look something like this... <h2>Header</h2><p>all the <span class="bright">content</span> here</p> I am interested in manipulating the string by reversing all the words. For example ...

How can you achieve the functionality of jQuery's hide() and show() in JavaScript?

Is there a JavaScript equivalent to my simple hide and show jQuery code? Here is my current code: $(document).ready(function() { $("#myButton").hide(); $("#1").click(function() { $("#myButton").show(); $("#myButton").click(function() { ...

Reasons Behind Slow Unmounting of React Components

In my current project, I have implemented a component that wraps multiple ReactList components. The ReactList component features infinite scrolling, meaning it only loads what is currently in the viewport. There are two modes available - simple and uniform ...

How to retrieve data from a form object sent via cloud function using App Script

Currently, I am in the process of developing a web application that can extract files from a web form and store them in a designated Google Drive folder. After the user submits the form, my goal is to trigger a cloud function using google.script.run while ...

When encountering error code EINTEGRITY during npm installation, a warning about a potentially corrupted tarball may be displayed

I have been facing an issue for the last three days with my react+vite project on Windows 10. Whenever I attempt to install dependencies using npm install, I encounter the following error: npm WARN tarball tarball data for fast-levenshtein@https://registry ...

A guide on incorporating java.type into your JavaScript code

I've been attempting to utilize the following command in my JavaScript: var file = new Java.type("java.io.File"); Unfortunately, I'm encountering an error: Uncaught ReferenceError: Java is not defined Can anyone provide guidance on how to suc ...

Is the presence of a potential leak suggested by this arrangement in the heap snapshot retainer hierarchy

While analyzing a Heap snapshot, I came across a retainer hierarchy that looks like this: https://i.sstatic.net/Zg3bJ.png Is it possible that the MuiThemeProviderOld element (highlighted in yellow and from the @material-ui/core library) is causing a memo ...

We are unable to retrieve file content through Django's restful API

I have integrated Django restful API with AngularJS. Now, I am trying to upload files to the server using AngularJS and Django RESTful API. On the front-end, the HTML code is: <input type="file" data-upload-file id="uploadInputFile"> The AngularJS ...