title: LINQ to SQL with if statement
body: <p>I have a :</p>
  
  <pre><code>            var query = db.vw_web_GetAccounts; //a sql view
              if (some condition)
              {
                  query.Where(...);
              }
              else
              {
                  query.Where(...);
              }
              query.Select(a =&gt;  new AccountVM
              {
                  Name = a.Name,
                  ....
              });
  
              return query.ToList();
  </code></pre>
  
  <p>I want to return <code>List&lt;AccountVM&gt;</code></p>
  
  <p>There is an compilation error:</p>
  
  <pre><code>Error   CS0029  Cannot implicitly convert type 'System.Data.Entity.DbSet&lt;vw_web_GetAccounts&gt;' to 'System.Collections.Generic.List&lt;AccountVM&gt;'
  </code></pre>
  
  <p>Without the if condition example: It works as expected</p>
  
  <pre><code>var query = db.vw_web_GetAccounts
              .Where(...)
              .Select(a =&gt; new AccountVM
              {
                  Name = a.Name,
                  ....
              });
  
              return query.ToList();
  </code></pre>
  
  <p>How do I make it work with if condition?</p>