GridView Sort using LINQ2SQL with multiple tables
<p>I’m trying to sort a GridView using LINQ2SQL with multiple tables. Since the columns in the grid contain data from several tables how do I tell LINQ which column name to sort by. </p>

<p>For example the user clicks on the first column (<code>POCNum</code>) which is in table <code>p</code> so I would use <code>p.POCNum</code> to <code>orderby</code>. Problem is <code>e.SortExpressio</code>n only contains the word <code>POCNum</code>. No way to link this back to table <code>p</code>. So if somebody clicks on column <code>Contact_ID</code> which is in table <code>c</code> I need to <code>orderby c.Contact_ID</code> in the LINQ query.</p>

<p>Any suggestions would be appreciated.</p>

<pre><code>protected void GridView1_Sort(Object sender, GridViewSortEventArgs e)
{
     DataClasses1DataContext db = new DataClasses1DataContext();
     var results = (from p in db.POCs&lt;BR/&gt;
                   join c in db.Contacts on p.POC_ID equals c.POC_ID
                   join a in db.Auxilaries on p.POC_ID equals a.POC_ID
                   join l in db.Legends on p.Basis equals l.Legend_code_value
                   orderby e.SortExpression // problem - 
                   //e.SortExpression does not contain table reference         
                   where p.DebtorObj_ID == Convert.ToInt32(ddlDebtor.SelectedItem.Value)
                   select new { p.POC_ID, p.POC_Date, p.POCNum, p.Total_Amt, p.Secure_Amt,
                                a.AMailing_Name1, l.Legend_Description }).ToList();
            GridView1.DataSource = results;
            GridView1.DataBind();
}
</code></pre>
