I have a code snippet that uses let with a where clause.
private List<string> Example2()
{
var query1 =
from c in _context.Customers
let custPurchases = _context.Purchases.Where(p => p.CustomerId == c.Id)
where custPurchases.Any(x => x.Price > 500)
select c.Name;
return query1.ToList();
}
It compiles well, but I get such an error during execution:
System.InvalidOperationException: The query contains a projection 'c => DbSet() .Where(p => p.CustomerId == c.Id)' of type 'IQueryable'. Collections in the final projection must be an 'IEnumerable' type such as 'List'. Consider using 'ToList' or some other mechanism to convert the 'IQueryable' or 'IOrderedEnumerable' into an 'IEnumerable'.
Why does EF Core try to execute this code on the client side instead of on the server (database)? Where does EF Core encounter the problem during translation IQueryable to SQL?
P.S.
LINQPad 8 by default easily executes this code, but that's LINQ-to-SQL:

Maybe you can provide some literature or links to dig deeper into the expression tree world?
I use SQL Server provider at LinqPad. Connection string is "Data Source=.;Integrated Security=SSPI;TrustServerCertificate=true;app=LINQPad".
CustomerandPurchaseentities? Not the tables, the C# classes ? Also what are you actually using? EF Core is a completely different ORM from LINQ-to-SQL, which came out in 2007 more as a demo of LINQ than a full featured ORM. It was never migrated to .NET Core