Projection expression: x.Id.Left(x.Id.IndexOf('.'))) no longer works in C# Driver version 2.22.0+

We have recently migrated from Server to 6.0.10 and this projection expression no longer works using the C# driver:

 var filter = Builders<PksXmlConfigFile>.Filter.Eq("Type", DocType.Config);
 var entityNames = await _Context.Database.GetCollection<PksXmlConfigFile>(collectionName)
 	.Project(x => x.Id.Left(x.Id.IndexOf('.')))

We receive the following error:

I have searched the change logs, but it isn’t apparent that any fixes related to this occurred. This worked fine in previous driver releases prior to 2.22.0. We tried Driver version 2.23.1 and it gives the same exception with the expression not being supported.

MongoDB.Driver.Linq.ExpressionNotSupportedException: 'Expression not supported: x.Id.Left(x.Id.IndexOf(.))

Hi, Bill,

Thanks for reaching out. Previously in LINQ2 (our earlier LINQ provider), x.Id.Left would have resulted in a client-side projection. With LINQ3, we opted not to implicitly perform client-side projections requiring users to explicitly opt into LINQ-to-Objects. This could be done by performing a ToList() or similar operation on the query followed by a LINQ-to-Objects call via Select to perform the client-side projection.

While this made the performance implications of the user’s code clearer (the server and client side portions were clearly articulated with less magic), some users were relying on this behaviour. We are reconsidering this design decision and may support client-side projections in LINQ3 much as we did in LINQ2. You can follow CSHARP-4763 for updates.

In the meantime, you can work around the lack of client-side projections in LINQ3 using the LINQ-to-Objects technique mentioned above (which is what LINQ2 does internally anyways). Hope that helps.