ADO.NET DataService记录计数

时间:2010-05-17 04:34:28

标签: c# wcf-data-services

我使用ADO.NET Entity Framework将一些记录存储到数据库中。我想知道在C#.Net中使用ADO.NET Entity Framework的特定表中的总记录数     我给出了一些例子,但它没有用。

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

当我运行此代码时,我遇到了一些异常“处理此请求时出错”。像这样。

由于

2 个答案:

答案 0 :(得分:1)

int count = context.table.Count();

编辑:

很明显,您实际上是在查询ADO.Net DataService。虽然后端可能是EF,但您尝试从中获取计数的API不是。

您添加的代码看起来是正确的。我将假设问题不在语法中。

你什么时候得到错误?

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

答案 1 :(得分:0)

您可以获取有关错误的更多信息,以便准确了解错误的发生点 - http://blogs.msdn.com/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx

希望这有帮助。

由于 PRATIK