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'm using Lightspeed 3.0 with Repository Pattern. My first impression was that I had to prefetch all the relations that I need to work with on the UI in my repository, where an instance of UnitOfWorkScope is available, but I found out that when the Entity is out of Repository scope, it can still fetch the data for missing (lazy) relations. Is that a feature? I'm trying to understand how Lightspeed works under the hood. The question is that what happens if the entity is sent across the boundary where database is not available (e.g. WCF) (not that it is a good idea, but for the sake of the argument).
|
|
|
The requirement is that the entity must be registered with a non-disposed unit of work when it comes to load the relations. Thus, if your repository is using, say, a PerRequestUnitOfWorkScope, that creates a UOW, and that UOW remains alive for the duration of the Web request (assuming you don't explicitly dispose it). So entities in that UOW can load associations at any time during that Web request. On the other hand, if your repository worked like this: public Product GetProductById(int id) { then you could NOT traverse lazy-loaded associations on the returned Product, because the Product's UOW was now disposed. Similarly, if you serialise an entity and send it to another process, it could not load its associations because when deserialised it would not be associated with a UOW. You would need to attach it to a UOW before it could load the associations. This is also a reason why entities should not be stored in session state -- when you pull them out of session state on a subsequent request their UOWs might (should!) be disposed. |
|