LINQPad:如何使用 MetaTable 类型获取表中的行数?
在 LINQPad 中,我尝试打印数据库中的所有表以及每个表中的行数:
this.Mapping.GetTables().Select(o => new { TableName = o.TableName, RowCount = ? })
如何计算行数?
In LINQPad, I'm trying to print all tables in a database and row count in each of them:
this.Mapping.GetTables().Select(o => new { TableName = o.TableName, RowCount = ? })
How the row count can be calculated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我需要做同样的事情,并且我只查看包含数据的表。我很快发现您必须小心从这里提取的内容,因为数据是深度嵌套的。下面的查询在我的机器上运行不到一秒,数据库中有大约 266 个表(不包括视图)。
我希望这能回答你的问题。
I had a need to do the same thing and I was looking ONLY the tables that contained data. I found out pretty quickly that you have to be careful of what you pull back from here because the data is deeply nested. The query below took less than a second to run on my machine and I have approximately 266 tables (not including views) in the database.
I hope that this answers your question.
感谢Jason 的回答展示了如何按名称查找表。
Kudos to this answer from Jason for showing how to look up a table by name.
试试这个:
Try this:
试试这个:
Try this:
或者不使用映射:
Or without using Mapping :
这不是 LinqPad 问题,而是 Linq 问题。但让我给你一个很好的 LinqPad 技巧。将 .Dump() 添加到您的查询中,看看您会得到什么 - 非常酷。
This is not a LinqPad issue, but rather a Linq issue. But let me give you a nice LinqPad tip. Add .Dump() to your query and see what you get - very cool.