1.

What are the pros and cons of different types of loading?

Answer»

1. Lazy Loading

Pros

  • When the relationships are not too high, use Eager Loading. So you can reduce further queries on the server by using Eager Loading.
  • If you KNOW that related entities will be used everywhere with the main entity, use Eager Loading.

Cons

  • Adding the extra lines of code to implement lazy load makes the code more complicated.
  • It can affect a website's search engine ranking sometimes because the unloaded content is not properly indexed.

2. Eager Loading

Pros

  • Upon executing the code, the system initializes or loads the resource.
  • Additionally, related entities that are referenced by a resource must be pre-loaded.
  • It is advantageous when resources need to be loaded in the background.
  • It saves you time by avoiding the need to execute extra SQL queries.

Cons

  • Since everything must be loaded to begin RUNNING, starting the application TAKES a longer time.

Choosing the right tool

  • When you know you will use related entities with your main entity everywhere, use Eager Loading.
  • You should use Lazy Loading WHENEVER you have one-to-many collections.
  • Use lazy loading only if you are sure you won't need related entities right away.
  • When you are unsure about whether or not an entity will be used, use explicit loading after you have turned off Lazy Loading.


Discussion

No Comment Found