title: How does one sort using Entity Framework Dynamic "SortBy" string on a complex object?
body: <p>I am writing an entity framework query that maps to a complex object of objects. I am using jquery datatables which passes over the query sort dynamically as a string typical like "item_id" or "item_id DESC". When passed into a SoryBy clause, it sorts the database results be the item id column. This is fine if that is the base object, but if I have a wrapper object which contains the object, it says item id is not defined for type ItemInfo.</p>
  
  <p>A mockup of the classes are as follows.</p>
  
  <pre><code>public class Item {
      public int item_id { get; set; }
      public int category_id { get; set; }
  }
  
  public class ItemCategory {
          public String category { get; set; }
          public int category_id { get; set; }
      }
  
  public class ItemInfo {
          public Item item { get; set; }
          public ItemCategory category { get; set; }
      }
  </code></pre>
  
  <p>What does the string for the .SortBy clause need to be to get the item_id from Item in an ItemInfo query?</p>
  
  <pre><code>IQueryable&lt;ItemInfo&gt; query = (from i in Item
                                join c in ItemCategory on i.category_id equals c.category_id
                                select new ItemInfo() {
                                   item = i,
                                   category = c
                                };
  </code></pre>