title: OrderBy a date field with linq and return ToList()
body: <p>i am gettting a list of records from table, its working fine, but when i use orderby its showing a error if i use this code like this its working fine :</p>
  
  <pre><code>var Item = from itm in DB.Items
  orderby itm.ExpiryDate ascending
  select new Item
  {
  
  };
  return Item.ToList();
  </code></pre>
  
  <p>above is working fine, but i have a condition so thats why i need to use the following which is giving a error</p>
  
  <pre><code>var Item = from itm in DB.Items
  select new Item
  {
  </code></pre>
  
  <p>};</p>
  
  <pre><code>if (Order == "NearExpire")
  {
  return Item.OrderBy(e=&gt;e.ExpiryDate).ToList();
  }
  else
  {
  return Item.ToList();
  }
  </code></pre>
  
  <p>Here is Solution</p>
  
  <pre><code>var Item = (from itm in DB.Items
  select new Item
  {
  
  }).ToList();
  
  if (Order == "NearExpire")
  {
  return Item.OrderBy(e=&gt;e.ExpiryDate).ToList();
  }
  else
  {
  return Item.ToList();
  }
  </code></pre>