New Posts New Posts RSS Feed: Skip, Take and Count
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Skip, Take and Count

 Post Reply Post Reply
Author
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 Topic: Skip, Take and Count
    Posted: 25-Aug-2011 at 12:05pm
Mickan,
 
Projections will return only the entity part you selected (not the entire entity). There is an article in the DevForce Resource Center that explains this topic in detail.
 
When working n-tier, no entities will be loaded into the BOS when returning a count.
 
Silvio.
Back to Top
mickan View Drop Down
Newbie
Newbie


Joined: 20-Apr-2011
Location: Atlanta
Posts: 6
Post Options Post Options   Quote mickan Quote  Post ReplyReply Direct Link To This Post Posted: 25-Aug-2011 at 11:13am
Silvio, thanks thats very helpful, especially the code sample.   To dig a little deeper:
 
Do projections behave the same way, or will they result in data row transfer?
With a BOS involved, will there be data row retrival into the BOS in either of the entity or projection cases when returning a count?
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: 25-Aug-2011 at 10:53am
Hi mickan,
 
Yes, Count() causes immediate execution of the query, but that doesn't mean that all the records have been returned to the client.
 
You can verify that:
 
  mgr.Clear();
  var ordersCount = mgr.Orders.Count(); // will return the number of Orders in the datasource
  var orders = mgr.Orders.With(QueryStrategy.CacheOnly).Execute(); // will be empty because no Orders were loaded in the client
 
or, if working asynchronously:
 
  mgr.Clear();
  var ordersCountOp = mgr.Orders.AsScalarAsync().Count();
  ordersCountOp.Completed += (o, args) => {
    var ordersCount = ordersCountOp.Result; // will return the number of Orders in the datasource
    var orders = mgr.Orders.With(QueryStrategy.CacheOnly).Execute(); // will be empty because no Orders were loaded in the client
  };
 
To answer your questions:
1. Only the requested rows will be transfered from the data source.
2. Not necessary. (given explanation about Count() above)
3. If you are retriving a really large number of records and it's causing your app to 'hang' during this retrieval, I'd suggest issuing 2 queries: one for the records that will populate the first grid page and other for all records.
 
Regards,
   Silvio.
Back to Top
mickan View Drop Down
Newbie
Newbie


Joined: 20-Apr-2011
Location: Atlanta
Posts: 6
Post Options Post Options   Quote mickan Quote  Post ReplyReply Direct Link To This Post Posted: 24-Aug-2011 at 7:26am
From what I've read on the board I think I understand that the linq Count() operation causes immediate execution of the query.  So if the query was to return thousands of rows that would be "unfortunate" for the user, especially over a wan.
 
I can use Skip() and Take() to chunk the data retrieval, but my Xceed grid wants a count of possible records, presumably to display the thumb slider at an appropriate size and do other housekeeping for "virtualizing" the data presentation.
 
So my questions are:
 
1. Are skip() and take() executed in the BOS so that only the requested rows get transferred from the data source?
2. Is requesting an implementation of a linq extension, say ToCount(), a reasonable ask of the DevForce linq provider?
3. Any better suggestions for me than having two methods for potentially large queries in my repository, such as
 
IList GetLotsOfEntities();
int    GetLotsOfEntitiesCount();
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down