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
|
Hi,
I'm now making decision which O/R Mapper to use.
I just wanna know:
uow.Products.Where(p => p.Category == Category.Cars)
Does it means automatically database query? Or does UOW implement Identity Map? Or are somehow objects stored in UOW?
Beforehand I want to take a note that this has no influence to my decision.
I just wanna know how does it works.
Thank you, Pooik
|
|
|
Hi Pooik, It will automatically generate a database query. The UoW does implement an internal identity map to ensure that if you subsequently requested the same object it would return it from the identity map rather than fetch it from the database. You get the best of both worlds. This mean the identity map effectively works as a level 1 cache for fetched objects to ensure good performance. I hope that helps - let me know if you have any further questions :-) John-Daniel Trask |
|
|
Hi John-Daniel, it's great. I'm starting own company and I'm looking for some little framework to start up for building my application on. I'm playing with LightSpeed around today and I think I just decided :) But what do you think by "subsequently requested same object"? Like another Where method call (if I understand, another Where method call makes another query, but taking already loaded objects from Identity Map??)? Is it described somewhere? Thanks a lot |
|
|
Your description in your final paragraph is correct. Suppose you do the following query: uow.Products.Where(p => p.Category == Category.Cars) and it happens to return the Products with IDs 1, 2 and 3. Those three entities are now registered in the unit of work (the identity map). Now suppose that, using the same unit of work, you do the following query: uow.Products.Where(p => p.Price < 1000) and this happens to return the Products with IDs 3, 4 and 5. Now LightSpeed notices that Product #3 is already in the identity map, so it returns the existing, loaded Product instead of creating a new one. (This is what JD means by "subsequently requesting the same object" -- you've issued a new query where an already-loaded entity is part of the result set.) Products #4 and #5 are not in the identity map so it creates new objects for them. Similarly, if you repeat the original Category query, LightSpeed will re-issue the database query. It doesn't remember that it's already performed this query, and it doesn't try to run the query against the identity map. But, assuming that the database returns the same results, the object instances will be the already-loaded ones. So queries always run against the database, but results can come from the existing identity map. Note this applies only within the same unit of work. Each unit of work has its own identity map. (You can also cache entities across units of work, but this is a different mechanism; see Caching in the docs.) I don't think the documentation has a detailed explanation of the identity map / L1 cache stuff, but the patterns are discussed and linked from the Architecture and Patterns and Unit of Work Mechanics pages in the help file under Help Topics > LightSpeed. Good luck with the startup! |
|
|
Oh man, great explanation, thanks a lot! And thanks for the wish! |
|