New Posts New Posts RSS Feed: how get record count using linq to devforce
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

how get record count using linq to devforce

 Post Reply Post Reply
Author
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post Topic: how get record count using linq to devforce
    Posted: 29-Jun-2010 at 11:10pm
Thanks kimj,
That solved my problem !
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 28-Jun-2010 at 12:24pm
Just as with standard LINQ or LINQ to EF, you can add the Count() operator to your query.  Count() is an "immediate execution" operator, which means you can't build a query containing the operator as you can with the usual deferred execution types of operators.  So you can do something like this: 
 
int ct = (from r in mgr.testTables where [condition] select r).Count();
 
If you're working in Silverlight then the query needs to be executed asynchronously, so you can do it like this:
      var op = (from r in mgr.testTables where [condition] select r).AsScalarAsync().Count();
      op.Completed += (o, e) => {
        int ct = e.Result;
      };
Back to Top
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post Posted: 27-Jun-2010 at 5:16am
No idea ???!!!
Back to Top
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2010 at 10:16pm

No, I dont mean get count of an argument of type IEnumerable ! I know how do that !!!

I need to get record count of a database table (I exactly mean something like SQL COUNT function).

Edited by ehsan - 25-Jun-2010 at 10:16pm
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: 25-Jun-2010 at 1:50pm

I am not sure what you mean by count of some special records, but here is an example of some code in the Learning Resources that reports a Fetch Count of an argument of type IEnumerable.

 private void ReportFetchCount(IEnumerable result, string entityType, string queryDescription) {
      int entitiesRetrieved = ((ICollection)result).Count;
      WriteMessage(string.Format("Retrieved {0} entities of type {1} using query of type {2}", entitiesRetrieved, entityType, queryDescription));
    }
Back to Top
ehsan View Drop Down
Newbie
Newbie
Avatar

Joined: 02-Jun-2010
Posts: 15
Post Options Post Options   Quote ehsan Quote  Post ReplyReply Direct Link To This Post Posted: 25-Jun-2010 at 12:17am
I've a query like this :

IEntityQuery<testTable> query = (from r in mgr.testTables where [condition] select r);

Now I want to get count of selected records, in linq to sql its possible to do this by adding .Count() at the end of linq query.

Here how can i get count of some special records ?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down