title: Sorting MultiValue data numerically OR alphabetically - LINQ to SQL and C#3
body: <p>I am having a problem giving a LINQ predicate the knowledge it needs to sort either alphabetically or numerically.</p>
  
  <p>I am working with a multi-value pivoted set of data with has a sortable column.  The column is always stored as varchar in the DB, however, it has lookup knowledge of what that data type actually is. To simplify, in addition to strings the column can contain integers.</p>
  
  <p>I have written a general-purpose (and working) sorting predicate as follows.</p>
  
  <pre><code>Func&lt;MyObject, string&gt; sortClause = p =&gt; p.MyObjectProperties.Find(s =&gt; s.Name == theSortProperty).Value;
  </code></pre>
  
  <p>The problem is that if my sortable column contains numerical values (stored as varchar in the DB), I get</p>
  
  <pre><code>13
  131   &lt;-- 131 between 13 and 14!!!
  14
  15 
  </code></pre>
  
  <p>Of course, alphanumerically this is correct.</p>
  
  <p>As I said, I know programmatically the type of data (string or integer) for theSortProperty. I want to be able to instruct the predicate to sort using alphabetical means OR numerical means. I see no easy way to accomplish this, since my LINQ to SQL mapping declares that column as [Column(Storage="_Value", DbType="NVarChar(MAX)", UpdateCheck=UpdateCheck.Never)]  </p>
  
  <p>Yet I am sure someone must have seen this before and can offer a suggestion. I should mention that NHibernate or other ORMs are out of the question for me.....Thanks</p>