Repository: dotnet/efcore
File: test/EFCore.Specification.Tests/Query/NorthwindMiscellaneousQueryTestBase.cs (C#)

Code before:
                      == (from e2 in ss.Set<Employee>().OrderBy(e => e.EmployeeID)
                          select e2).FirstOrDefault().FirstName
                  select e1);

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition2_FirstOrDefault_with_anonymous(bool async)
        => AssertQuery(
            async,
            ss => from e1 in ss.Set<Employee>().Take(3)
                  where e1.FirstName
                      == (from e2 in ss.Set<Employee>().OrderBy(e => e.EmployeeID)
                          select new { Foo = e2 }).FirstOrDefault().Foo.FirstName
                  select e1);

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition3(bool async)
        => AssertTranslationFailed(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>()
                      where c1.City == ss.Set<Customer>().OrderBy(c => c.CustomerID).First(c => c.IsLondon).City
                      select c1));

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition4(bool async)
        => AssertTranslationFailed(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>().OrderBy(c => c.CustomerID).Take(2)
                      where c1.City
                          == (from c2 in ss.Set<Customer>().OrderBy(c => c.CustomerID)
                              from c3 in ss.Set<Customer>().OrderBy(c => c.IsLondon).ThenBy(c => c.CustomerID)
                              select new { c3 }).First().c3.City
                      select c1));

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition5(bool async)
        => AssertTranslationFailedWithDetails(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>()
                      where c1.IsLondon == ss.Set<Customer>().OrderBy(c => c.CustomerID).First().IsLondon
                      select c1),
            CoreStrings.QueryUnableToTranslateMember(nameof(Customer.IsLondon), nameof(Customer)));

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]

Review comment (bug):
/cc @jaredpar @CyrusNajmabadi 

Here I got a CS9236, but oddly adding the typing information didn't make it go away (SDK 10.0.100-preview.6.25358.103). A naive attempt at a minimal repro didn't work (see code below). Let me know if there are known false positives like this or how I can help.

<details>
<summary>Failed attempted repro</summary>

```c#
await using var context = new CustomerContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();

await AssertTranslationFailed(
    () => AssertQuery(
        async: true,
        ss => from c1 in ss.Set<Customer>().OrderBy(c => c.CustomerID).Take(2)
                where c1.City
                    == (from c2 in ss.Set<Customer>().OrderBy(c => c.CustomerID)
                        // from c3 in ss.Set<Customer>().OrderBy(bool (Customer c) => c.IsLondon).ThenBy(string (Customer c) => c.CustomerID)
                        from c3 in ss.Set<Customer>().OrderBy(c => c.IsLondon).ThenBy(string (Customer c) => c.CustomerID)
                        select new { c3 }).First().c3.City
                select c1));

static Task AssertTranslationFailed(Func<Task> query)
    => throw new NotImplementedException();

Task AssertQuery<TResult>(
        bool async,
        Func<CustomerContext, IQueryable<TResult>> query,
        Func<TResult, object>? elementSorter = null,
        Action<TResult, TResult>? elementAsserter = null,
        bool assertOrder = false,
        bool assertEmpty = false,
        QueryTrackingBehavior? queryTrackingBehavior = null,
        [CallerMemberName] string testMethodName = "")
        => throw new NotImplementedException();

public class CustomerContext : DbContext;

public class Customer
{
    public required string CustomerID { get; set; }
    public required string City { get; set; }
    public bool IsLondon { get; set; }
}
```

</details>



Code after:
                      == (from e2 in ss.Set<Employee>().OrderBy(e => e.EmployeeID)
                          select e2).FirstOrDefault().FirstName
                  select e1);

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition2_FirstOrDefault_with_anonymous(bool async)
        => AssertQuery(
            async,
            ss => from e1 in ss.Set<Employee>().Take(3)
                  where e1.FirstName
                      == (from e2 in ss.Set<Employee>().OrderBy(e => e.EmployeeID)
                          select new { Foo = e2 }).FirstOrDefault().Foo.FirstName
                  select e1);

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition3(bool async)
        => AssertTranslationFailed(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>()
                      where c1.City == ss.Set<Customer>().OrderBy(c => c.CustomerID).First(c => c.IsLondon).City
                      select c1));

#pragma warning disable CS9236 // Compiling requires binding the lambda expression at least 200 times
    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition4(bool async)
        => AssertTranslationFailed(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>().OrderBy(c => c.CustomerID).Take(2)
                      where c1.City
                          == (from c2 in ss.Set<Customer>().OrderBy(c => c.CustomerID)
                              from c3 in ss.Set<Customer>().OrderBy(bool (Customer c) => c.IsLondon).ThenBy(string (Customer c) => c.CustomerID)
                              select new { c3 }).First().c3.City
                      select c1));
#pragma warning restore CS9236

    [ConditionalTheory]
    [MemberData(nameof(IsAsyncData))]
    public virtual Task Where_query_composition5(bool async)
        => AssertTranslationFailedWithDetails(
            () => AssertQuery(
                async,
                ss => from c1 in ss.Set<Customer>()
                      where c1.IsLondon == ss.Set<Customer>().OrderBy(c => c.CustomerID).First().IsLondon
                      select c1),
            CoreStrings.QueryUnableToTranslateMember(nameof(Customer.IsLondon), nameof(Customer)));