Skip to content

Commit 7417b4c

Browse files
authored
DOCSP-43911 - Implicit Client-Side Projection in LINQ3 (mongodb#242)
1 parent 88027b8 commit 7417b4c

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

source/whats-new.txt

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,77 @@ The 3.0 driver release includes the following new features:
8282
`TimeOnly Struct. <https://learn.microsoft.com/en-us/dotnet/api/system.timeonly?view=net-6.0>`__
8383
API reference page on MSDN.
8484

85+
- Adds support for implicit client-side projection when using the ``Find()`` method,
86+
the ``Select()`` method, or the ``Project()`` aggregation stage with the LINQ3 provider.
87+
In previous versions of the driver, you could perform client-side
88+
projection with the LINQ3 provider only after calling the ``ToEnumerable()`` or
89+
``AsEnumerable()`` method.
90+
91+
To learn how to enable and use client-side projection for a driver method, select the
92+
corresponding tab:
93+
94+
.. tabs::
95+
96+
.. tab:: Find() Method
97+
:tabid: find-method
98+
99+
.. code-block:: csharp
100+
101+
// Enable client-side projection
102+
var findOptions = new FindOptions();
103+
findOptions.TranslationOptions = new ExpressionTranslationOptions
104+
{
105+
EnableClientSideProjections = true
106+
};
107+
108+
var find = collection
109+
.Find(doc => doc.Id == 1, findOptions);
110+
.Project(doc => new { R = MyFunction(doc.Name) });
111+
112+
.. tab:: Select() Method
113+
:tabid: select-method
114+
115+
.. code-block:: csharp
116+
117+
// Enable client-side projection
118+
var aggregateOptions = new AggregateOptions();
119+
aggregateOptions.TranslationOptions = new ExpressionTranslationOptions
120+
{
121+
EnableClientSideProjections = true
122+
};
123+
124+
var queryable = collection
125+
.AsQueryable(aggregateOptions)
126+
.Where(doc => doc.Id == 1)
127+
.Select(doc => new { R = MyFunction(doc.Name) });
128+
129+
.. tab:: Project() Method
130+
:tabid: project-method
131+
132+
.. code-block:: csharp
133+
134+
// Enable client-side projection
135+
var aggregateOptions = new AggregateOptions();
136+
aggregateOptions.TranslationOptions = new ExpressionTranslationOptions
137+
{
138+
EnableClientSideProjections = true
139+
};
140+
141+
var aggregate = collection
142+
.Aggregate(aggregateOptions)
143+
.Project(doc => new { R = MyFunction(doc.Name) });
144+
145+
.. tip:: MongoClientSettings
146+
147+
To enable client-side projection for all queries on a client, set the
148+
``TranslationOptions`` property of the ``MongoClientSettings`` object to ``true``.
149+
150+
To learn more about using the aggregation pipeline with the {+driver-short+}, see
151+
:ref:`csharp-aggregation`.
152+
153+
For more information about this release, see the :github:`v3.0 release notes
154+
</mongodb/mongo-csharp-driver/releases/tag/v3.0.0>`.
155+
85156
.. _csharp-version-2.28:
86157

87158
What's New in 2.28

0 commit comments

Comments
 (0)