Print Page | Close Window

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

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4316
Printed Date: 11-Mar-2025 at 4:15pm


Topic: Navigation properties may be pending mode while they are already in the EntityManager's cache
Posted By: kdev
Subject: Navigation properties may be pending mode while they are already in the EntityManager's cache
Date 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,



Replies:
Posted By: sbelini
Date 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 - http://drc.ideablade.com/devforce-2012/bin/view/Documentation/navigation-properties-data-retrieval .


Posted By: kdev
Date 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 - 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,



Print Page | Close Window