You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: entity-framework/ef6/fundamentals/async.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -131,12 +131,12 @@ Now that we have an EF model, let's write some code that uses it to perform some
131
131
}
132
132
```
133
133
134
-
This code calls the **PerformDatabaseOperations** method which saves a new **Blog** to the database and then retrieves all **Blogs** from the database and prints them to the **Console**. After this, the program writes a quote of the day to the **Console**.
134
+
This code calls the `PerformDatabaseOperations` method which saves a new **Blog** to the database and then retrieves all **Blogs** from the database and prints them to the **Console**. After this, the program writes a quote of the day to the **Console**.
135
135
136
136
Since the code is synchronous, we can observe the following execution flow when we run the program:
137
137
138
-
1.**SaveChanges** begins to push the new **Blog** to the database
139
-
2.**SaveChanges** completes
138
+
1.`SaveChanges` begins to push the new **Blog** to the database
139
+
2.`SaveChanges` completes
140
140
3. Query for all **Blogs** is sent to the database
141
141
4. Query returns and results are written to **Console**
142
142
5. Quote of the day is written to **Console**
@@ -149,14 +149,14 @@ Since the code is synchronous, we can observe the following execution flow when
149
149
150
150
Now that we have our program up and running, we can begin making use of the new async and await keywords. We've made the following changes to Program.cs
151
151
152
-
1. Line 2: The using statement for the **System.Data.Entity** namespace gives us access to the EF async extension methods.
153
-
2. Line 4: The using statement for the **System.Threading.Tasks** namespace allows us to use the **Task** type.
154
-
3. Line 12 & 18: We are capturing as task that monitors the progress of **PerformSomeDatabaseOperations** (line 12) and then blocking program execution for this task to complete once all the work for the program is done (line 18).
155
-
4. Line 25: We've update **PerformSomeDatabaseOperations** to be marked as **async** and return a **Task**.
156
-
5. Line 35: We're now calling the Async version of SaveChanges and awaiting it's completion.
157
-
6. Line 42: We're now calling the Async version of ToList and awaiting on the result.
152
+
1. Line 2: The using statement for the `System.Data.Entity` namespace gives us access to the EF async extension methods.
153
+
2. Line 4: The using statement for the `System.Threading.Tasks` namespace allows us to use the `Task` type.
154
+
3. Line 12 & 18: We are capturing as task that monitors the progress of `PerformSomeDatabaseOperations` (line 12) and then blocking program execution for this task to complete once all the work for the program is done (line 18).
155
+
4. Line 25: We've update `PerformSomeDatabaseOperations` to be marked as `async` and return a `Task`.
156
+
5. Line 35: We're now calling the Async version of `SaveChanges` and awaiting it's completion.
157
+
6. Line 42: We're now calling the Async version of `ToList` and awaiting on the result.
158
158
159
-
For a comprehensive list of available extension methods in the System.Data.Entity namespace, refer to the QueryableExtensions class. *You’ll also need to add “using System.Data.Entity” to your using statements.*
159
+
For a comprehensive list of available extension methods in the `System.Data.Entity` namespace, refer to the `QueryableExtensions` class. *You’ll also need to add `using System.Data.Entity` to your using statements.*
160
160
161
161
```csharp
162
162
usingSystem;
@@ -216,11 +216,11 @@ For a comprehensive list of available extension methods in the System.Data.Entit
216
216
217
217
Now that the code is asynchronous, we can observe a different execution flow when we run the program:
218
218
219
-
1.**SaveChanges** begins to push the new **Blog** to the database
220
-
*Once the command is sent to the database no more compute time is needed on the current managed thread. The **PerformDatabaseOperations** method returns (even though it hasn't finished executing) and program flow in the Main method continues.*
219
+
1.`SaveChanges` begins to push the new **Blog** to the database
220
+
*Once the command is sent to the database no more compute time is needed on the current managed thread. The `PerformDatabaseOperations` method returns (even though it hasn't finished executing) and program flow in the Main method continues.*
221
221
2.**Quote of the day is written to Console**
222
-
*Since there is no more work to do in the Main method, the managed thread is blocked on the Wait call until the database operation completes. Once it completes, the remainder of our **PerformDatabaseOperations** will be executed.*
223
-
3.**SaveChanges** completes
222
+
*Since there is no more work to do in the Main method, the managed thread is blocked on the `Wait` call until the database operation completes. Once it completes, the remainder of our `PerformDatabaseOperations` will be executed.*
223
+
3.`SaveChanges` completes
224
224
4. Query for all **Blogs** is sent to the database
225
225
*Again, the managed thread is free to do other work while the query is processed in the database. Since all other execution has completed, the thread will just halt on the Wait call though.*
226
226
5. Query returns and results are written to **Console**
Copy file name to clipboardExpand all lines: entity-framework/ef6/fundamentals/proxies.md
+10-8Lines changed: 10 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ When creating instances of POCO entity types, Entity Framework often creates ins
10
10
11
11
## Disabling proxy creation
12
12
13
-
Sometimes it is useful to prevent Entity Framework from creating proxy instances. For example, serializing non-proxy instances is considerably easier than serializing proxy instances. Proxy creation can be turned off by clearing the ProxyCreationEnabled flag. One place you could do this is in the constructor of your context. For example:
13
+
Sometimes it is useful to prevent Entity Framework from creating proxy instances. For example, serializing non-proxy instances is considerably easier than serializing proxy instances. Proxy creation can be turned off by clearing the `ProxyCreationEnabled` flag. One place you could do this is in the constructor of your context. For example:
14
14
15
15
```csharp
16
16
publicclassBloggingContext : DbContext
@@ -29,7 +29,7 @@ Note that the EF will not create proxies for types where there is nothing for th
29
29
30
30
## Explicitly creating an instance of a proxy
31
31
32
-
A proxy instance will not be created if you create an instance of an entity using the new operator. This may not be a problem, but if you need to create a proxy instance (for example, so that lazy loading or proxy change tracking will work) then you can do so using the Create method of DbSet. For example:
32
+
A proxy instance will not be created if you create an instance of an entity using the new operator. This may not be a problem, but if you need to create a proxy instance (for example, so that lazy loading or proxy change tracking will work) then you can do so using the `Create` method of `DbSet`. For example:
33
33
34
34
```csharp
35
35
using (varcontext=newBloggingContext())
@@ -38,7 +38,7 @@ using (var context = new BloggingContext())
38
38
}
39
39
```
40
40
41
-
The generic version of Create can be used if you want to create an instance of a derived entity type. For example:
41
+
The generic version of `Create` can be used if you want to create an instance of a derived entity type. For example:
42
42
43
43
```csharp
44
44
using (varcontext=newBloggingContext())
@@ -47,17 +47,19 @@ using (var context = new BloggingContext())
47
47
}
48
48
```
49
49
50
-
Note that the Create method does not add or attach the created entity to the context.
50
+
Note that the `Create` method does not add or attach the created entity to the context.
51
51
52
-
Note that the Create method will just create an instance of the entity type itself if creating a proxy type for the entity would have no value because it would not do anything. For example, if the entity type is sealed and/or has no virtual properties then Create will just create an instance of the entity type.
52
+
Note that the `Create` method will just create an instance of the entity type itself if creating a proxy type for the entity would have no value because it would not do anything. For example, if the entity type is sealed and/or has no virtual properties then `Create` will just create an instance of the entity type.
53
53
54
54
## Getting the actual entity type from a proxy type
55
55
56
56
Proxy types have names that look something like this:
You can find the entity type for this proxy type using the GetObjectType method from ObjectContext. For example:
62
+
You can find the entity type for this proxy type using the `GetObjectType` method from `ObjectContext`. For example:
61
63
62
64
```csharp
63
65
using (varcontext=newBloggingContext())
@@ -67,4 +69,4 @@ using (var context = new BloggingContext())
67
69
}
68
70
```
69
71
70
-
Note that if the type passed to GetObjectType is an instance of an entity type that is not a proxy type then the type of entity is still returned. This means you can always use this method to get the actual entity type without any other checking to see if the type is a proxy type or not.
72
+
Note that if the type passed to `GetObjectType` is an instance of an entity type that is not a proxy type then the type of entity is still returned. This means you can always use this method to get the actual entity type without any other checking to see if the type is a proxy type or not.
0 commit comments