---
title: "Computing row count in linq?"  
description: "Computing row count in linq?"  
author: "Anonymous User"  
published: 2015-02-17  
updated: 2015-02-17  
canonical: https://www.mindstick.com/forum/12961/computing-row-count-in-linq  
category: "c#"  
tags: ["c#", "linq"]  
reading_time: 1 minute  

---

# Computing row count in linq?

I am [exploring](https://yourviews.mindstick.com/view/85453/trends-of-the-space-race-and-the-moon-landing-exploring-new-frontiers) a very messy SQL-[Database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) via LINQPAD and I would like to get a list of all [tables](https://www.mindstick.com/articles/336597/introduction-of-html-tables-for-web-development) where at [least](https://yourviews.mindstick.com/story/1471/5-autobiographies-you-should-read-at-least-once) one [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) is of type [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp). Furthermore, I would like to compute the [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) of [distinct](https://www.mindstick.com/forum/159558/why-c-sharp-linq-distinct-doesn-t-work) [values](https://www.mindstick.com/forum/327/sum-textbox-values) for each column mentioned above.

I have tried to jumble something [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-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 } )}
```

## Replies

### Reply by Anonymous User

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}",

member.Name,

table.TableName)).FirstOrDefault()

select new { table.TableName, member.Name, count }


---

Original Source: https://www.mindstick.com/forum/12961/computing-row-count-in-linq

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
