title: Entity Framework query optimisation and code mutualisation
body: <p>I have a web application with a single table and 2 screens:</p>
  <ul>
  <li>A listing screen with Id, Name, Calc1 and Calc2 fields (this screen contains filters and pagination)</li>
  <li>A detail screen with Id, Name, Calc1, Calc2 and Calc3 fields</li>
  </ul>
  <p>Fields Id and Name come from the database.</p>
  <p>Calc1, Calc2 and Calc3 fields are very complex expressions. These expressions are written in C# and they are translated into SQL by EF.</p>
  <p>Here is my query structure:</p>
  <pre><code>var query = from t in mydbcontext.mytable 
              where ...
              select new MyViewModel {
                 Id = t.Id,
                 Name = t.Name,
                 Calc1 = xxx + yyy - zzz/2 ...
                 Calc2 = www + ee + eg/2 ...
                 Calc3 = sdf + df - dg/2 ...
              }
  </code></pre>
  <p>This query is stored in a common Service.</p>
  <p>Calc1,2,3 are calculations but also contains data lookup (in other tables).</p>
  <p>query is an IQueryable object. This is very important because i have filters and pagination on my listing screen.</p>
  <p>I am working with this query in my full application. I don't want to implement Calc1, Calc2 and Calc3 in multiple parts of my code.</p>
  <p>It works fine but i have a problem: Calc3 is calculated everytime. But this information is not necessary in the listing screen.</p>
  <p>I cannot remove it because i need this information in the second screen.</p>
  <p>My question is how can i do ?</p>
  <p>I have tried several approaches but this approaches needs to work with List&lt;&gt; instead of IQuerayble&lt;&gt; and i want to work only with IQuerayble. (for example i have tried to put Calc expressions in C# functions)</p>
  <p>Thanks</p>