title: Linq to entities query with nested query on the same table
body: <p>I have a SQL query:</p>
  
  <pre><code>SELECT distinct A.stock_value_site,
                  A.BALANCE_QUANTITY,
                  A.BALANCE_NOMINAL_VALUE, 
                  A.BALANCE_INDEXED_VALUE,
                  V.STOCK_VALUE_ORDER,
                  U.BALANCE_QUANTITY  
  FROM            svr A,   
                  svt V,
                  svu U
  WHERE V.Code = 500 and  
        A.Id = U.ID (+) and
        A.Id = (SELECT    max(B.id) 
                FROM      svr B,
                          sts
                WHERE     A.stock_value_site = B.stock_value_site and 
                          B.Id = sts.ID(+) and
                          B.item = _item and 
                          B.date &lt; _from_date and
                          B.Id IS NULL)
  </code></pre>
  
  <p>I tried to convert this query to Linq to entities:</p>
  
  <pre><code>var data = (from A in _context.svr
             join V in _context.svt on A.svtId equals V.Code
             join U in _context.svu on A.Id equals U.Id into groupA
             from gA in groupA.DefaultIfEmpty()
             where V.Code == _openBalanceRecordId &amp;&amp;
                   A.Id == (from B in _context.svr
                            join st in _context.sts on B.Id equals st.Id into groupB
                            from gB in groupB.DefaultIfEmpty()
                            where A.svsId == B.svsId &amp;&amp;
                                  B.ItemId == _item &amp;&amp;
                                  B.Date &lt; _startDate.Date
                            select B.Id).Max()
             select new
             {
                 A.stock_value_site,
                 A.BALANCE_QUANTITY,
                 A.BALANCE_NOMINAL_VALUE, 
                 A.BALANCE_INDEXED_VALUE,
                 V.STOCK_VALUE_ORDER,
                 gA == null ? 0 : gA.BALANCE_QUANTITY
             }).Distinct().ToList();
  </code></pre>
  
  <p>When I run the SQL query in oracle I get 33 records back. But when I run it using Linq to entities I don't get any record. </p>
  
  <p>What am I doing wrong?</p>