From 45a6d4a16bb11e6c09d2ad2eca45f27f7b8c2578 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Thu, 3 Oct 2024 16:44:58 -0500 Subject: [PATCH] DOCSP-43911 - Implicit Client-Side Projection in LINQ3 (#242) --- source/whats-new.txt | 71 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/source/whats-new.txt b/source/whats-new.txt index 67195842..d4afdbe7 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -82,6 +82,77 @@ The 3.0 driver release includes the following new features: `TimeOnly Struct. `__ API reference page on MSDN. +- Adds support for implicit client-side projection when using the ``Find()`` method, + the ``Select()`` method, or the ``Project()`` aggregation stage with the LINQ3 provider. + In previous versions of the driver, you could perform client-side + projection with the LINQ3 provider only after calling the ``ToEnumerable()`` or + ``AsEnumerable()`` method. + + To learn how to enable and use client-side projection for a driver method, select the + corresponding tab: + + .. tabs:: + + .. tab:: Find() Method + :tabid: find-method + + .. code-block:: csharp + + // Enable client-side projection + var findOptions = new FindOptions(); + findOptions.TranslationOptions = new ExpressionTranslationOptions + { + EnableClientSideProjections = true + }; + + var find = collection + .Find(doc => doc.Id == 1, findOptions); + .Project(doc => new { R = MyFunction(doc.Name) }); + + .. tab:: Select() Method + :tabid: select-method + + .. code-block:: csharp + + // Enable client-side projection + var aggregateOptions = new AggregateOptions(); + aggregateOptions.TranslationOptions = new ExpressionTranslationOptions + { + EnableClientSideProjections = true + }; + + var queryable = collection + .AsQueryable(aggregateOptions) + .Where(doc => doc.Id == 1) + .Select(doc => new { R = MyFunction(doc.Name) }); + + .. tab:: Project() Method + :tabid: project-method + + .. code-block:: csharp + + // Enable client-side projection + var aggregateOptions = new AggregateOptions(); + aggregateOptions.TranslationOptions = new ExpressionTranslationOptions + { + EnableClientSideProjections = true + }; + + var aggregate = collection + .Aggregate(aggregateOptions) + .Project(doc => new { R = MyFunction(doc.Name) }); + + .. tip:: MongoClientSettings + + To enable client-side projection for all queries on a client, set the + ``TranslationOptions`` property of the ``MongoClientSettings`` object to ``true``. + + To learn more about using the aggregation pipeline with the {+driver-short+}, see + :ref:`csharp-aggregation`. + +For more information about this release, see the :github:`v3.0 release notes +`. + .. _csharp-version-2.28: What's New in 2.28