New Posts New Posts RSS Feed: Unexpected loading from the database
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Unexpected loading from the database

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

Joined: 21-May-2009
Location: Iceland
Posts: 81
Post Options Post Options   Quote tj62 Quote  Post ReplyReply Direct Link To This Post Topic: Unexpected loading from the database
    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?
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: 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 DevForce Resource Center.
 
Silvio.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down