Cached property vs Lazy

I would use Lazy<T> in general: It’s thread-safe (may not be an issue in this case, but would be in others) It makes it obvious what’s going on just by the name It allows null to be a valid value Note that you don’t have to use a lambda expression for the delegate. For example, … Read more

infinite scroll with ember.js (lazy loading)

I’ve implemented an infinite scroll mechanism at the GitHub Dashboard project, I’m currently developing. The feature is added in commit 68d1728. The basic idea is to have a LoadMoreView which invokes the loadMore method on the controller every time the view is visible on the current viewport. I’m using the jQuery plugin inview for this. … Read more

How to test whether lazy loaded JPA collection is initialized?

Are you using JPA2? PersistenceUnitUtil has two methods that can be used to determine the load state of an entity. e.g. there is a bidirectional OneToMany/ManyToOne relationship between Organization and User. public void test() { EntityManager em = entityManagerFactory.createEntityManager(); PersistenceUnitUtil unitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil(); em.getTransaction().begin(); Organization org = em.find(Organization.class, 1); em.getTransaction().commit(); Assert.assertTrue(unitUtil.isLoaded(org)); // users is a … Read more

Disable lazy loading by default in Entity Framework 4

The following answer refers to Database-First or Model-First workflow (the only two workflows that were available with Entity Framework (version <= 4.0) when the question was asked). If you are using Code-First workflow (which is available since EF version >= 4.1) proceed to ssmith’s answer to this question for a correct solution. The edmx file … Read more

Is it bad practice to have my getter method change the stored value?

I think it is actually quite a bad practice if your getter methods change the internal state of the object. To achieve the same I would suggest just returning the “N/A”. Generally speaking this internal field might be used in other places (internally) for which you don’t need to use the getter method. So in … Read more

Doctrine 2 ArrayCollection filter method

Doctrine now has Criteria which offers a single API for filtering collections with SQL and in PHP, depending on the context. https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/working-with-associations.html#filtering-collections Update This will achieve the result in the accepted answer, without getting everything from the database. use Doctrine\Common\Collections\Criteria; /** * @ORM\Entity */ class Member { // … public function getCommentsFiltered($ids) { $criteria = … Read more