title: Selecting a column based on another column's value with LINQ
body: <p>My question is similar to the one here: <a href="https://stackoverflow.com/questions/3338710/select-a-specific-column-based-on-another-columns-value">Select a specific column based on another column&#39;s value</a> but in LINQ, using VS2010, C#, .Net 4.0 and LINQ to Entities</p>
  
  <p>Here's the snippet I'm having an issue with: </p>
  
  <pre><code>var BillingNumbers = (from o in mycontext.MyOrders
                      where o.Status.Description.Trim().ToUpper().Equals("SHIPPED")
                      &amp;&amp; (o.ActualShipDate &gt;= date1.Date &amp;&amp; o.ActualShipDate &lt; date2.Date)
                      select new
                              {BillingNumber = (
                            o.SiteID == "NYC"? o.NYCBillingNumber.Trim():
                            o.SiteID == "DAL" ? o.DallasBillingNumber.Trim(): "unknown") 
                            });
               foreach (var billingnumber in BillingNumbers)
               {
                  sqlcmd = MyDatabase.GetStoredProcCommand("MyBillingNumberSP") as SqlCommand;
                  sqlcmd.CommandTimeout = Int32.Parse(Settings.Default.SQL_COMMAND_TIMEOUT.ToString());
                  MyDatabase.AddInParameter(sqlcmd, "@BillingNumber", DbType.String, billingnumber);
                  MyDatabase.AddOutParameter(sqlcmd, "@MyOutputParam", DbType.Boolean, 1);
                  LobjDS = MyDatabase.ExecuteDataSet(sqlcmd);  //GETTING AN ERROR HERE
                  bool JobbingApplied = Convert.ToBoolean(MyDatabase.GetParameterValue(sqlcmd, "@MyOutputParam"));
                  Console.WriteLine(billingnumber);
               }
  </code></pre>
  
  <p>The ExecuteDataSet command throws an InvalidCastException with the message:</p>
  
  <blockquote>
    <p>Failed to convert parameter value from a &lt;>f__AnonymousType0`1 to a String.</p>
  </blockquote>
  
  <p>What is wrong and why is this anonymous type throwing an error when attempted to interpret it as string? </p>