New Posts New Posts RSS Feed: Question about entity manager cache & top x queries
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Question about entity manager cache & top x queries

 Post Reply Post Reply
Author
gepi View Drop Down
Newbie
Newbie


Joined: 07-Jun-2010
Location: Austria
Posts: 2
Post Options Post Options   Quote gepi Quote  Post ReplyReply Direct Link To This Post Topic: Question about entity manager cache & top x queries
    Posted: 08-Jun-2010 at 3:53am

Hi
 
I have the following code:
 
EntityQuery eq = new IdeaBlade.Persistence.EntityQuery(typeof(SomeEntity));

eq.Top = 50;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

this works fine, but every time I run this query (in an session) it fetches the data form the database.It never fetches the data form the cache.
My understanding of the  Persistancemanager Cache is that it should fetch the data the first time form the DataSource, the times after it should fetch it from the cache. Is this right?
 
The other point is that if run this sequence:
EntityQuery eq = new IdeaBlade.Persistence.EntityQuery(typeof(SomeEntity));

eq.Top = 0;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

eq.Top = 50;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

than the second query is fetching its data from the cache.
 
is there a special behavior for "top" query?
Do I miss something?
 
kind regards

Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 08-Jun-2010 at 11:02am
If you had written the query in OQL, the PersistenceManager would have found the entities in the cache. but you can't use TOP in OQL.  The Developer's Guide says:
 
OQL Limitations

OQL can cover most of the searches we need. There are useful queries that we can‟t express in OQL.

OQL queries always return business objects. Therefore, OQL cannot express a query with a result that does not map to business object.

This restriction eliminates any query that describes the fields of a Select statement. We can‟t choose to return just the [FirstName] but not the [LastName] because an Employee object expects both. Aggregates (sum, min, max, average, etc.) and calculated fields are out94.

We can‟t write OQL equivalents to SQL statements that include:

calculated comparisons (PriceEntityColumn x QuantityEntityColumn > 100)

GROUP BY and HAVING clauses ("orders with more than 3 items")

ANY and ALL

UNION

TOP

Therefore, I am assuming that you used a PassThruQuery, and the PersistenceManager does not cache the results of a PassThruQuery.

Back to Top
gepi View Drop Down
Newbie
Newbie


Joined: 07-Jun-2010
Location: Austria
Posts: 2
Post Options Post Options   Quote gepi Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jun-2010 at 7:12am
Hi David
 
Thank you for your fast answer.
 
Unfortunally I do not use a PaaThruQuery. It is a normal EntityQuery in which I set the Top property.
It seems that there is a difference between queries, in which the Top property is set, and in which this property is set to 0:
When I set the Top property, the query is not added to the QueryCache and it always fetches the data form the database (except I use the CacheOnly Query Strategy).
 
If I run the same query without setting this property than everything is fine - the second time I run the query the data are fetched from cache.
 
kind regards
 
Georg
 
 
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 09-Jun-2010 at 1:36pm

When a query has a non-zero Top operator it’s not saved to the QueryCache.

So, for the questions in the first post  -

EntityQuery eq = new IdeaBlade.Persistence.EntityQuery(typeof(SomeEntity));

eq.Top = 50;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

This will go back to datasource each time it’s run because the query wasn’t placed in the QueryCache.

 Second part -

EntityQuery eq = new IdeaBlade.Persistence.EntityQuery(typeof(SomeEntity));

eq.Top = 0;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

eq.Top = 50;

_PMCentral.GetEntities<T>(eq,QueryStrategy.Normal)

The first query was added to the QueryCache because the Top operator was 0.  On subsequent execution, even though the Top operator has now been set to 50, DevForce will first look in the QueryCache to see if the query has been executed.  It finds the query, and runs the query against cache, applying the Top operator locally.

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down