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: aspnetcore/blazor/blazor-ef-core.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -62,15 +62,15 @@ The sample app was built as a reference for server-side Blazor apps that use EF
62
62
63
63
The sample uses a local [SQLite](https://www.sqlite.org/index.html) database so that it can be used on any platform.
64
64
65
-
The sample demonstrates use of EF Core to handle optimistic concurrency. However, [native database-generated concurrency tokens](/ef/core/saving/concurrency?tabs=fluent-api#native-database-generated-concurrency-tokens) aren't supported for SQLite databases, which is the database provider for the sample app. To demonstrate concurrency with the sample app, adopt a different database provider that supports database-generated concurrency tokens (for example, the [SQL Server provider](/ef/core/providers/sql-server)).
65
+
The sample demonstrates use of EF Core to handle optimistic concurrency. However, [native database-generated concurrency tokens](/ef/core/saving/concurrency?tabs=fluent-api#native-database-generated-concurrency-tokens) aren't supported for SQLite databases, which is the database provider for the sample app. To demonstrate concurrency with the sample app, adopt a different database provider that supports database-generated concurrency tokens (for example, the [SQL Server provider](/ef/core/providers/sql-server)). You can adopt SQL Server for the sample app by following the guidance in the next section, *Use the sample with SQL Server and optimistic concurrency*.
66
66
67
67
### Use the sample with SQL Server and optimistic concurrency
68
68
69
69
The sample demonstrates use of EF Core to handle optimistic concurrency but only for a database provider that uses [native database-generated concurrency tokens](/ef/core/saving/concurrency?tabs=fluent-api#native-database-generated-concurrency-tokens), which is a feature supported for SQL Server. To demonstrate concurrency with the sample app, the sample app can be converted from the SQLite provider to use the [SQL Server provider](/ef/core/providers/sql-server) with a new SQL Server database created using .NET scaffolding.
70
70
71
71
Use the following guidance to adopt SQL Server for the sample app using Visual Studio.
72
72
73
-
Open the `Program` file (`Program.cs`) and comment out the lines that add the SQLite provider:
73
+
Open the `Program` file (`Program.cs`) and comment out the lines that add the database context factory with the SQLite provider:
@@ -87,25 +87,25 @@ In the **Add New Scaffolded Item** dialog, select **Installed** > **Common** > *
87
87
88
88
In the **Add Razor Components Using Entity Framework (CRUD)** dialog, use the following settings:
89
89
90
-
***Template**: Leave the selection on **CRUD**.
91
-
***Model class**: Select the `Contact` model.
90
+
***Template**: Use the default selection (**CRUD**).
91
+
***Model class**: Select the `Contact` model from the dropdown list.
92
92
***DbContext class**: Select the plus sign (`+`) and select **Add** using the default context class name generated by the scaffolder.
93
-
***Database provider**: Leave the default **SQL Server** value.
93
+
***Database provider**: Use the default selection (**SQL Server**).
94
94
95
95
Select **Add** to scaffold the model and create the SQL Server database.
96
96
97
97
When the scaffolding operation completes, delete the generated context class from the `Data` folder (`Data/{PROJECT NAME}Context.cs`, where the `{PROJECT NAME}` placeholder is the project's name/namespace).
98
98
99
99
Delete the `ContactPages` folder from the `Components/Pages` folder, which contains [QuickGrid](xref:blazor/components/quickgrid)-based pages for contact management. For a complete demonstration of QuickGrid-based pages for managing data, use the <xref:blazor/tutorials/movie-database-app/index> tutorial.
100
100
101
-
Open the `Program` file (`Program.cs`) and find the line that scaffolding added to create a database context factory using the SQL Server provider. Change the context from the generated context class (deleted earlier) to the existing `ContactContext` class:
101
+
Open the `Program` file (`Program.cs`) and find the line that scaffolding added to create a database context factory using the SQL Server provider. Change the context from the generated context class (deleted earlier) to the app's existing `ContactContext` class:
At this point, the app is using the SQL Server provider and a SQL Server database created for the `Contacts` model class. Optimistic concurrency works using [native database-generated concurrency tokens](/ef/core/saving/concurrency?tabs=fluent-api#native-database-generated-concurrency-tokens) that are already implemented in the sample app's code.
108
+
At this point, the app is using the SQL Server provider and a SQL Server database created for the `Contact` model class. Optimistic concurrency works using [native database-generated concurrency tokens](/ef/core/saving/concurrency?tabs=fluent-api#native-database-generated-concurrency-tokens) that are already implemented in the sample app's `ContactContext` class.
0 commit comments