Skip to content

Commit 3170695

Browse files
committed
wip
1 parent b3a1e69 commit 3170695

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

source/fundamentals/serialization/polymorphic-objects.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,19 @@ you must explicitly list each class you're looking for:
156156
.. code-block:: csharp
157157
:copyable: true
158158

159-
var query = coll.Aggregate().Match(a => a is Cat || a is Lion || a is Tiger);
159+
var query = coll.AsQueryable().Where(
160+
item => item.GetType() == typeof(Cat) ||
161+
item.GetType() == typeof(Lion) ||
162+
item.GetType() == typeof(Tiger));
163+
164+
.. note:: OfType<T>() and the is Operator
165+
166+
When checking the type of a scalar discriminator, use the ``Where`` syntax shown in
167+
the preceding code example. If you try to use the ``Aggregate().OfType<T>()`` method,
168+
or if you pass an expression containing the ``is`` operator to the
169+
``Aggregate().Match()`` method, the driver throws an exception.
170+
171+
.. _csharp-discriminator-hierarchical:
160172

161173
HierarchicalDiscriminatorConvention
162174
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

source/upgrade/v3.txt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,31 @@ Version 3.0 Breaking Changes
203203
property instead.
204204

205205
- The driver removes individual cluster events from ``MongoClient.Cluster``. To listen for
206-
cluster events, use `ClusterBuilder.Subscribe() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Configuration.ClusterBuilder.Subscribe.html>`__.
206+
cluster events, call the `ClusterBuilder.Subscribe() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Configuration.ClusterBuilder.Subscribe.html>`__
207+
method.
208+
209+
- If any type in a collection uses a scalar discriminator, the driver throws
210+
an exception if you perform either of the following actions on the collection:
211+
212+
- Call the ``Aggregate().OfType<T>()`` method, as in the following example:
213+
214+
.. code-block:: csharp
215+
216+
collection.Aggregate().OfType<T>()
217+
218+
- Call the ``Aggregate().Match(item => item is T)`` method, as in the following example:
219+
220+
.. code-block:: csharp
221+
222+
collection.Aggregate().Match(item => item is T)
223+
224+
To use either of the preceding methods on a collection, you can apply a hierarchical
225+
discriminator to each class in the collection. See
226+
the :ref:`Polymorphic Objects <csharp-discriminator-hierarchical>`
227+
page to learn how to do so.
228+
229+
Alternatively, you can check each item's type in a different way. For example, you
230+
can call the item's ``GetType()`` method and compare the result to the type you're
231+
looking for, as shown here: ``item.GetType() == typeof(T)``
232+
233+
To learn more about type discriminators, see :ref:`<csharp-polymorphism>`.

0 commit comments

Comments
 (0)