File tree Expand file tree Collapse file tree 5 files changed +9
-5
lines changed
fundamentals/code-examples/configure Expand file tree Collapse file tree 5 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 7
7
// Replace the placeholder with your connection URI
8
8
var client = new MongoClient ( "<Your connection URI>" ) ;
9
9
var db = PlanetDbContext . Create ( client . GetDatabase ( "sample_planets" ) ) ;
10
- db . Database . EnsureCreated ( ) ;
11
10
// end-create-instance
12
11
13
12
void FindOne ( )
Original file line number Diff line number Diff line change 10
10
new DbContextOptionsBuilder < MyDbContext > ( ) . UseMongoDB ( mongoClient , "<Database Name>" ) ;
11
11
12
12
var db = new MyDbContext ( dbContextOptions . Options ) ;
13
- db . Database . EnsureCreated ( ) ;
14
13
15
14
// Add a new customer and save it to the database
16
15
db . Customers . Add ( new Customer ( ) { name = "John Doe" , Order = "1 Green Tea" } ) ;
Original file line number Diff line number Diff line change 3
3
var dbContextOptions =
4
4
new DbContextOptionsBuilder < MyDbContext > ( ) . UseMongoDB ( mongoClient , "<Database Name" ) ;
5
5
6
- var db = new MyDbContext ( dbContextOptions . Options ) ;
7
- db . Database . EnsureCreated ( ) ;
6
+ var db = new MyDbContext ( dbContextOptions . Options ) ;
Original file line number Diff line number Diff line change 13
13
}
14
14
var client = new MongoClient ( connectionString ) ;
15
15
var db = MflixDbContext . Create ( client . GetDatabase ( "sample_mflix" ) ) ;
16
- db . Database . EnsureCreated ( ) ;
17
16
18
17
var movie = db . Movies . First ( m => m . Title == "Back to the Future" ) ;
19
18
Console . WriteLine ( movie . Plot ) ;
Original file line number Diff line number Diff line change @@ -72,6 +72,14 @@ Version 8.1.0 Breaking Changes
72
72
creating the collection or database
73
73
implicitly.
74
74
75
+ .. note::
76
+
77
+ Calling the ``EnsureCreated()`` or ``EnsureCreatedAsync()`` method throws
78
+ an error if your application is running on a
79
+ :atlas:`shared cluster </reference/free-shared-limitations/>`.
80
+ Applications running on free and shared clusters should not call these
81
+ methods.
82
+
75
83
If you don't want to ensure :wikipedia:`optimistic concurrency
76
84
<Optimistic_concurrency_control>` with transactions, you can
77
85
disable automatic transactions by setting ``Database.AutoTransactionBehavior =
You can’t perform that action at this time.
0 commit comments