title: Optimize LINQ queries
body: <p>I'd like to optimize my LINQ query.</p>
  
  <pre><code>Orders = (from m in dataContext.SupplierOrdersViews
            where (fromDate != toDate ?
                   m.RecordCreated &gt;= fromDate &amp;&amp; m.RecordCreated &lt;= toDate :
                   (m.RecordCreated.Value.Year == fromDate.Year &amp;&amp;
                    m.RecordCreated.Value.Month == fromDate.Month &amp;&amp;
                    m.RecordCreated.Value.Day == fromDate.Day))
            select new
            {
               id = m.ID,
               RecordCreated = m.RecordCreated,
               RecordDeleted = m.RecordDeleted,
               Status = m.Status,
               DepRunningNo = m.DepRunningNo,
               Name = m.Name,
               Address1 = m.Address1,
               VehicleRegNo = m.VehicleRegNo,
               ProductName = m.ProductName,
               Tare = m.Tare &lt; m.Gross ? m.Tare : m.Gross,
               Gross = m.Tare &lt; m.Gross ? m.Gross : m.Tare,
               NetWeight = m.NetWeight,
               NetPrice = m.NetPrice
            }).OrderBy(m =&gt; m.RecordCreated).ThenByDescending(m =&gt; m.Status != 2).ToList();
  </code></pre>
  
  <p>I think the issue is with these lines:</p>
  
  <p><code>Tare = m.Tare &lt; m.Gross ? m.Tare : m.Gross,</code></p>
  
  <p><code>Gross = m.Tare &lt; m.Gross ? m.Gross : m.Tare,</code></p>
  
  <p>How does this work behind the scenes, and is there a better way to accomplish it?  I'm happy that it works but its not perfect.  This populates a grid with (using default filters) 77 records and it takes like 3 seconds...way too long!</p>
  
  <p>Is there a better way to assign gross/tares?  I need to do a check similar to what I have here because the weights are ambiguously stored in the database.</p>