@@ -23,9 +23,9 @@ Overview
2323{+framework-core+} allows you to work with data in your application without
2424explicitly running database commands. You can insert, update, or delete data
2525within your application and persist those changes to MongoDB by using the
26- ``SaveChanges()`` method.
26+ ``SaveChanges()`` or ``SaveChangesAsync()`` method.
2727
28- When you call the ``SaveChanges()`` method, the {+provider-short+} automatically detects
28+ When you call the ``SaveChanges()`` or ``SaveChangesAsync()`` method, the {+provider-short+} automatically detects
2929any changes made to your data and runs the necessary commands to update the
3030database by using the MongoDB Query API.
3131
@@ -37,13 +37,40 @@ an application configured to use the {+provider-short+}.
3737 To learn how to configure an application to use the {+provider-short+}, see
3838 :ref:`entity-framework-configure`.
3939
40+ Transactional Write Operations
41+ -------------------------------
42+
43+ The ``SaveChanges()`` and ``SaveChangesAsync()`` methods are transactional by
44+ default. This means that if an error occurs during an operation, the provider
45+ rolls back any changes made to the database. Because of this, your application
46+ must be connected to a transaction-capable deployment of MongoDB server, such as
47+ a replica set.
48+
49+ You can disable automatic transactions in the ``SaveChanges()`` and
50+ ``SaveChangesAsync()`` methods by setting the ``AutoTransactionBehavior`` property to
51+ ``AutoTransaction.Never`` on your ``DbContext`` subclass during application
52+ setup. However, we do not recommend disabling this feature. Doing so causes
53+ any concurrency changes or operation failures during the save operation
54+ to leave the database in an inconsistent state.
55+
56+ The following example shows how to disable automatic transactions in the
57+ ``SaveChanges()`` and ``SaveChangesAsync()`` methods:
58+
59+ .. code-block:: csharp
60+
61+ dbContext.Database.AutoTransactionBehavior = AutoTransactionBehavior.Never;
62+
63+ .. warning::
64+
65+ Disabling automatic transactions can lead to data inconsistencies. We
66+ recommend that you do not disable this feature.
67+
4068Insert
4169------
4270
4371You can use the ``Add()`` method to insert a single entity into your collection,
4472or you can use the ``AddRange()`` method to insert multiple entities at once.
4573
46-
4774.. _entity-framework-insert-one:
4875
4976Insert One Entity
0 commit comments