views:

152

answers:

2

Hi, I have stored some records in to database using ADO.NET Entity Framework. I want to know total record count in particular table using ADO.NET Entity Framework in C#.Net .
I given some example, but it is not working.

  EX:
  DataServiceQuery<BunHistory> query= context.BunHistory.IncludeTotalCount();
  QueryOperationResponse<BunHistory> response                                         
                        query.Execute() as QueryOperationResponse<BunHistory>;
  long count = response.TotalCount;

When i run this code i got some exception "An error occurred while processing this request." like this.

Thanks

+1  A: 
int count = context.table.Count();

EDIT:

It is becoming apparent that you are actually querying an ADO.Net DataService. While the backend may be EF, the API you are trying to get a count from is not.

The code you added looks correct. I am going to assume that the problem is not in the syntax.

At what point do you get the error?

Also: see http://blogs.msdn.com/peter_qian/archive/2009/03/18/getting-row-count-in-ado-net-data-services.aspx

Sky Sanders
When i run this code i got some exception "An error occurred while processing this request." like this.
Ravi
A: 

You can get more information about the error so that you know exactly what point the error is happening - http://blogs.msdn.com/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

Hope this helps.

Thanks Pratik

Pratik Patel