This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I was recently reading more into eager vs lazy loading in Lightspeed and Named Aggregates, as I was approaching a situation where I knew it would make more sense to load everything from the database is one shot rather than per access. My question is regarding entity associations, and whether or not duplicate entities are loaded from the database and/or stored multiple times in memory. For example. I have a Member entity and a Purchase entity, with each Member having one or more Purchases (one-to-many) Now if I pull a collection of Purchases, as in: var purchases = uow.Purchases.Where(p => p.Fulfilled).WithAggregate("WithAllData").ToList() where "WithAllData" is defined in the Member-Purchase Backreference Aggregate, this will eager load the Member associated with each Purchase. The question: If two or more of the Purchases share the same Member, will this Member entity's data appear multiple times in the database response and/or will it be stored multiple times in memory (once for each purchase.Memory), or does each purchase.Member act as a pointer to a shared piece of memory? If the former is true, I'm afraid there would be quite a bit of redundant data loaded from the DB and stored in memory. -Tony |
|
|
The latter - there is only one copy of an entity in the current UnitOfWork. If you are performing a FindById query and the entity matching that Id has already been loaded into the current UnitOfWork then we will not issue a query for this. Any other query where we dont know what entities match will be queried for normally however if we see an entity which has already been attached to the current UnitOfWork then the instance that already exists in the UnitOfWork will be returned rather than a fresh instance.
|
|