New Posts New Posts RSS Feed: Navigation properties may be pending mode while they are already in the EntityManager's cache
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Navigation properties may be pending mode while they are already in the EntityManager's cache

 Post Reply Post Reply
Author
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Topic: Navigation properties may be pending mode while they are already in the EntityManager's cache
    Posted: 10-Sep-2013 at 3:20am
Hi,

Lets say I have this model :

public class Person
{
   EntityRelatedList<Order> Orders {}
}

public class Order
{
   EntityRelatedList<OrderDetail> OrderDetails{}
}

public class OrderDetail
{
   public Category Category {}   
}

public class Category
{
}

I preload (using cocktail) the Category entities.
When I load a Person I include his Orders. OrderDetails are lazyloaded when the user want to see a specific Order.
Once the OrderDetails are loaded, I would expect them to be linked to the Categories already in my EntityManager's cache but they are not.
Every Category navigation property are in Pending mode and are currently being retreived from the database.

Shouldn't they use the Categories from the cache and not try to load them from the database ?

Regards,
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 10-Sep-2013 at 9:55am
kdev,

You might want to set:

OrderDetail.PropertyMetadata.Category.GetEntityReference(myOrderDetail).IsLoaded = true;


There are also other ways you can control the data retrieval of navigation properties and you will find them at http://drc.ideablade.com/devforce-2012/bin/view/Documentation/navigation-properties-data-retrieval.

Edited by sbelini - 10-Sep-2013 at 9:56am
Back to Top
kdev View Drop Down
Groupie
Groupie
Avatar

Joined: 03-Jan-2013
Posts: 83
Post Options Post Options   Quote kdev Quote  Post ReplyReply Direct Link To This Post Posted: 10-Sep-2013 at 10:46am
Hi Silvio,

Thank you,

After thinking more on this subject I think I understand why it's the normal behavior.

By default an EM get the entities from the datasouce then from cache. It will query from the cache only if it find the EXACT same query in its cache.
The preloader is a cocktail feature and works only when using a PreloadRepository because its strategy is to read from the cache only.
And because of this strategy, these queries aren't save in the EM Query Cache. That is why the property is lazy loaded from the database.

In the documentation (http://drc.ideablade.com/devforce-2012/bin/view/Documentation/query-cache) I can read

"The EntityManager will search the local cache instead of the database only if it "believes" that all essential information necessary to perform the query are resident in the cache"

Does that means that is I query ALL the entities of type EntityA then I query Entity.ID = 4 the second will hit the cache only (the second query doesn't exist in the cache) ?


Regards,
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down