Home > DeveloperSection > Forums > Computing row count in linq?
Pawan Shukla
Pawan Shukla

Total Post:29

Posted on    February-17-2015 6:20 AM

 C# C#  LINQ 

 1 Reply(s)
 987  View(s)
Rate this:

I am exploring a very messy SQL-Database via LINQPAD and I would like to get a list of all tables where at least one column is of type string. Furthermore, I would like to compute the count of distinct values for each column mentioned above.

I have tried to jumble something together, but my LINQ is rusty and anyway I have used it mainly for LINQ to Objects...

foreach(var table in Mapping.GetTables())



from dm in table.RowType.DataMembers

where dm.Type == typeof(string)

select new { dm.Name , dm.DbType , dm.Type , dm.MappedName, dm.IsPrimaryKey }



Alex Leblois
Alex Leblois

Total Post:67

Posted on    February-17-2015 6:23 AM

from table in Mapping.GetTables()

from member in table.RowType.DataMembers

where member.Type == typeof(string)

let count = ExecuteQuery<int>(String.Format(

                "SELECT COUNT(DISTINCT {0}) FROM {1}",



select new { table.TableName, member.Name, count }

Don't want to miss updates? Please click the below button!

Follow MindStick