Print Page | Close Window

Unexpected loading from the database

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2453
Printed Date: 16-Sep-2025 at 4:57pm


Topic: Unexpected loading from the database
Posted By: tj62
Subject: Unexpected loading from the database
Date Posted: 20-Jan-2011 at 4:31am
Hi,
I have a query like this:

        var query = p_manager.EntItemSet.Include("p_icon")

                      .OrderBy(p => p.p_friendlyName)

                      .Where(p => p.p_customerID == parent.p_customerID &&

                                   p.p_pointID == parent.p_pointID &&

                                   p.p_groupID == parent.p_groupID &&

                                   p.p_deviceItem.p_visible > 0);

What I have noticed is that because of the last where criteria "p.p_deviceItem.p_visible > 0" , the Entity items for "p.p_deviceItem" are loaded too from the database and put into the Entity Cash on the client.
It looks like this last where criteria is performed in the Entity Model but not in the Database Engine that would of course be faster and eliminate loading the p_deviceItem Entities from the database.
Why is this such? Can this be avoided?



Replies:
Posted By: sbelini
Date Posted: 24-Jan-2011 at 11:19am
Hi tj62,
 
This is a consequence of query inversion. (From wiki: "Query inversion is the process of retrieving those non-targeted objects that are nonetheless necessary for correct completion of a query")
 
The reason for that is is so that the query can be applied against a pool of data that combines unpersisted local data with data that exists in the datasource.
 
If you want to avoid this behavior, you should query the DataSourceOnly. (setting QueryInversionMode to Off will also set the QueryStrategy to DataSource only)
 
You can find more info about QueryInversion in our http://drc.ideablade.com/xwiki/bin/view/Documentation/EntityCaching_QueryStrategy - DevForce Resource Center .
 
Silvio.



Print Page | Close Window