title: LINQ query succeeding/error depends on one arbitrary assignment statement
body: <p>Here is my LINQ query in C#:</p>
  
  <pre><code>var q =
      from a in context.tableA.Where(s =&gt; s.field1 == id)    //I'm querying by "id"
      from b in context.tableB.Where(s =&gt; s.field1 == a.field1)
      from c in context.tableC.Where(s =&gt; s.field2 == b.field2).DefaultIfEmpty() //left join
      from d in context.tableD.Where(s =&gt; s.field3 == b.field3).DefaultIfEmpty()
      from e in context.tableE.Where(s =&gt; s.field4 == b.field4).DefaultIfEmpty()
  
      select new CustomObject()
      {
          CustomObject_fieldA = a.someField,
          CustomObject_fieldB = b.someField,
  
              //some other fields assigned...
  
          CustomObject_fieldC = c.someField,
          CustomObject_fieldD = d.someField,
          CustomObject_fieldE = e.someField     // &lt;-- THIS LINE
      }
  </code></pre>
  
  <p>So for clarification, my tables are structured like this:</p>
  
  <pre><code>tableA:    int field1
  tableB:    int field1   int field2   int field3   int field4
  tableC:                 int field2
  tableD:                              int field3
  tableE:                                           int field4
  </code></pre>
  
  <p><em>MY PROBLEM</em></p>
  
  <p>If I comment out <code>THIS LINE</code> then the query will succeed.</p>
  
  <p>If I leave <code>THIS LINE</code> uncommented, then the query will hang, and give <code>EntityCommandExecutionException</code> error (a <code>Timeout expired</code> error).</p>
  
  <p>Since I'm doing left joins, I know that <code>e</code> could be <code>NULL</code>. But I've done some tests that tell me this is not causing the error.</p>
  
  <p><em>--TEST 1--</em></p>
  
  <p>First, comment out <code>THIS LINE</code>. Then, <code>c</code> and <code>d</code> may or may not be <code>NULL</code>, and the query will succeed regardless of whether <code>c</code> or <code>d</code> are <code>NULL</code>.</p>
  
  <p><em>--Test 2--</em></p>
  
  <p>Uncomment <code>THIS LINE</code>. Whether <code>e</code> is <code>NULL</code> or not, the query will always fail (hang with the error given above).</p>
  
  <p><em>QUESTION</em></p>
  
  <p>I have run lots of testing and narrowed the success/failure(hanging) to depending on the commenting or uncommenting of <code>THIS LINE</code>.</p>
  
  <p><strong>Does anyone know why this is happening and how to fix it?</strong></p>
  
  <p><em>EDIT for clarification</em></p>
  
  <pre><code>// in the CustomObject.cs file, some of the properties are
  public string CustomObject_fieldA { get; set; }
  public string CustomObject_fieldB { get; set; }
  public string CustomObject_fieldC { get; set; }
  public string CustomObject_fieldD { get; set; }
  public string CustomObject_fieldE { get; set; }
  </code></pre>