tags:

views:

32

answers:

2

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?

A: 

Try this:

var list = this.Mapping.GetTables()
    .Select(o => new { TableName = o.TableName, Type_ = o.Row.Type, RowCount = 0 }).ToList();

list.ForEach(x=>x.RowCount  = this.GetTable(x.Type_).Count);
list.Select(o=> new { TableName = o.TableName, RowCount = 0 });
Nix
That is flat-out not good. Why would you want to send a direct SQL statement through to the DB and bypass all the strong type checking available with Linq queries?
Randy Minder
Hes using LinqPad not a production system, its a sandbox.
Nix
@Nix - Doesn't matter. Still a bad suggestion. That is sloppy programming, and doesn't address the issue.
Randy Minder
A: 

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.

this.Mapping.GetTables().Select(o => new { TableName = o.TableName, RowCount = ? }).Dump()
Randy Minder
How adding Dump help here? I know the Dump method and know it's very cool, but how it's relates to this question?
Kamarey
@Kamarey - Did you try it? It will show you the row counts.
Randy Minder
I don't get how the Dump can help here? Where should I add it to see what you are talking about?
Kamarey