title: EF Core 3.1 generates ORDER BY (SELECT 1) which breaks old code
body: <p>I'm upgrading our project from .NET Core 2.1 to 3.1 and am facing the following issue with EF Core.</p>
  <p>I have the following code:</p>
  <pre><code>var all = this.Context.Devices.OrderBy(c =&gt; c.Id).Where(predicate).Distinct();
  var result = await all.Skip(pagedRequest.Offset).Take(pagedRequest.Limit).ToListAsync();
  var totalCount = await all.CountAsync();
  </code></pre>
  <p>This is basically used for pagination and also gives the total element count to the client. Predicate is a dynamically generated filter condition. Why is Distinct() really used I haven't figured out yet (it's some old code I'm facing). One may well argue if it's needed, but that's certainly valid, and so does not change the question.
  However the following SQL is generated:</p>
  <pre><code> SELECT [d].[Id], ...
  FROM [Device] AS [d]
  WHERE ([d].[State] = 2) AND EXISTS (
      SELECT 1
      FROM [AnotherTable] AS [r]
      WHERE ([d].[Id] = [r].[DeviceId]) AND ([r].[UserId] = 1))
  ORDER BY (SELECT 1)
  OFFSET 0 ROWS FETCH NEXT 50 ROWS ONLY
  </code></pre>
  <p>And than I get <code>ORDER BY items must appear in the select list if SELECT DISTINCT is specified.</code>
  It was not appearing in .net ef 2.1. I looked at the breaking changes and didn't find anything that could explain it. Also I don't understand what the heck is <code>ORDER BY (SELECT 1)</code> and why is it generated instead of order by id.</p>
  <p>I've checked now the SQL generated with the same code but EF 2.1. It's exactly the same only that there is <code>ORDER BY [c].[Id]</code> instead of <code>ORDER BY (SELECT 1)</code>, as I would expect.</p>
  <p>Can somebody explain this behaviour?</p>
  <p>P.S.: another interesting thing is that if I hover over <code>all</code> in debugger and see the Results view, I see there the objects. Exception comes from the second code line where Skip and Take are added.</p>