The following works in LINQ2 but not in LINQ3:
var find = collection .Find(x => x.Id == 1) .Project(x => new { R = MyFunction(x.X) }); // MyFunction cannot be translated to MQL
The following doesn't work with either LINQ provider:
var queryable = collection.AsQueryable() .Where(x => x.Id == 1) .Select(x => new { R = MyFunction(x.X) }); // MyFunction cannot be translated to MQL
When writing the new LINQ3 provider we made the deliberate decision to not support implicit client side projections for the following reasons:
- they only work on the final Select
- adding any additional stages after a final Select with implicit client side projections breaks the query
- they can hide inefficiency because more data than expected might be fetched to the client
We felt that client side projections should be explicit so that users writing and reading code know exactly what is happening server side and what is happening client side.
The above two examples can be refactored to use explicit client side projections as follows:
var find = collection .Find(x => x.Id == 1) .ToEnumerable() // execute the rest of this chain client side .Select(x => new { R = MyFunction(x.X) });
and
var enumerable = collection.AsQueryable() .Where(x => x.Id == 1) .AsEnumerable() // execute the rest of this chain client side .Select(x => new { R = MyFunction(x.X) });
While our decision to not support implicit client side projections is reasonable, nonetheless it is a breaking change from LINQ2 (at least with respect to `Find`). In addition, in spite of the potential inefficiencies that implicit client side projections might hide some users want the convenience of it anyway.
- is duplicated by
-
CSHARP-4588 LINQ3 LinqProvider do not support public extension method
- Closed
-
CSHARP-4548 IFindFluent.Projection fails with ExpressionNotSupportedException after upgrading to 2.19.0
- Closed
-
CSHARP-4498 .Project(c => c.Reference()) not work
- Closed
-
CSHARP-4705 ExpressionNotSupportedException with projection expression
- Closed
-
CSHARP-4956 ExpressionNotSupported Exception after updating to 2.19
- Closed
- is related to
-
CSHARP-5321 Optimize client-side projections to only fetch the parts of the document that are needed for the projection
- Ready for Work
- related to
-
EF-76 Select projection rewriting
- Backlog
-
CSHARP-4759 Improve error message for client side projections
- Backlog