title: Exclude columns where all rows in that column are null or equal to 0 in LINQ
body: <p>I need to exclude a column from a DataSet Query where that column only contains 0's (Nulls).</p>
  
  <p>All solutions I have found (for example: <a href="https://stackoverflow.com/questions/401935/filtering-null-values-in-select">Filtering Null values in Select</a>) only process the condition per row and won't take into to account all the values in the column as I need.</p>
  
  <p>The query needs to be generic to be used across multiple different data tables so I cannot explicitly state column names to exclude.</p>
  
  <p>The latest code I've tried is:</p>
  
  <pre><code>theTable = result.Tables[0];
  var query = theTable.AsEnumerable().Select(r =&gt; r.ItemArray.Where(c =&gt; long.Parse(c.ToString()) != 0));
  </code></pre>
  
  <p>This excludes all 0's in the row, but it does not maintain the column structure and I end up with rows with different Lengths (column sizes).</p>
  
  <p>This is my example SQL for reference:</p>
  
  <pre><code>SELECT t1.TableIndex
  , CASE WHEN t1.EntityName &lt;&gt; t2.EntityName THEN 1 ELSE 0 END AS EntName
  , CASE WHEN t1.EntityNumber &lt;&gt; t2.EntityNumber THEN 1 ELSE 0 END AS EntNumber
  
  FROM DbEnv.dbo.tblOne t1 (NOLOCK)
  INNER JOIN DbEnv.dbo.tblTwo t2 (nolock) ON t1.TableIndex = t2.TableIndex
  
  WHERE t1.EntityName &lt;&gt; t2.EntityName
  OR t1.EntityNumber &lt;&gt; t2.EntityNumber
  </code></pre>
  
  <p>Example Data Set (In this scenario, only Col2 should be excluded):</p>
  
  <pre><code>     Col1 | Col2 | Col3
  Row1: 0      0      1
  Row2: 1      0      1
  Row3: 0      0      0
  </code></pre>
  
  <p>Example Data Set 2 (In this scenario, Col1 and Col4 should be excluded):</p>
  
  <pre><code>     Col1 | Col2 | Col3 | Col4 | Col5
  Row1: 0      0      1      0      1
  Row2: 0      0      1      0      1
  Row3: 0      1      0      0      1
  Row3: 0      1      0      0      1
  </code></pre>
  
  <p><em>(Solution can be in SQL or LINQ, but I would think it would be cleaner to have the solution in LINQ)</em></p>