ADO.NET DataService 记录计数
我已使用 ADO.NET 实体框架将一些记录存储到数据库中。我想知道在 C#.Net 中使用 ADO.NET 实体框架的特定表中的总记录数。
我举了一些例子,但它不起作用。
EX:
DataServiceQuery<BunHistory> query= context.BunHistory.IncludeTotalCount();
QueryOperationResponse<BunHistory> response
query.Execute() as QueryOperationResponse<BunHistory>;
long count = response.TotalCount;
当我运行此代码时,出现一些异常“处理此请求时发生错误。”像这样。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以获得有关错误的更多信息,以便准确了解错误发生的位置 - http://blogs.msdn.com/phaniraj/archive/2008/06/18/debugging-ado-net-data-services.aspx
希望这有帮助。
谢谢
普拉蒂克
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
编辑:
很明显,您实际上正在查询 ADO.Net DataService。虽然后端可能是 EF,但您尝试从中获取计数的 API 却不是。
您添加的代码看起来是正确的。我假设问题不在于语法。
您在什么时候收到错误?
另:请参阅 http://blogs.msdn.com/peter_qian/archive/2009/03/18/getting-row-count-in-ado-net-data-services.aspx
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