Skip to content

Commit

Permalink
Fix getting started app
Browse files Browse the repository at this point in the history
Create the database with EnsureCreated instead of with Migrations.

Fixes #3078
  • Loading branch information
roji committed Feb 4, 2021
1 parent a30da26 commit b4e1cdf
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 221 deletions.
35 changes: 2 additions & 33 deletions entity-framework/core/get-started/overview/first-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,42 +92,11 @@ EF Core can also [reverse engineer](xref:core/managing-schemas/scaffolding) a mo

Tip: This application intentionally keeps things simple for clarity. [Connection strings](xref:core/miscellaneous/connection-strings) should not be stored in the code for production applications. You may also want to split each C# class into its own file.

## Create the database

The following steps use [migrations](xref:core/managing-schemas/migrations/index) to create a database.

### [.NET Core CLI](#tab/netcore-cli)

* Run the following commands:

```dotnetcli
dotnet tool install --global dotnet-ef
dotnet add package Microsoft.EntityFrameworkCore.Design
dotnet ef migrations add InitialCreate
dotnet ef database update
```

This installs [dotnet ef](xref:core/cli/dotnet) and the design package which is required to run the command on a project. The `migrations` command scaffolds a migration to create the initial set of tables for the model. The `database update` command creates the database and applies the new migration to it.

### [Visual Studio](#tab/visual-studio)

* Run the following commands in **Package Manager Console (PMC)**

```powershell
Install-Package Microsoft.EntityFrameworkCore.Tools
Add-Migration InitialCreate
Update-Database
```

This installs the [PMC tools for EF Core](xref:core/cli/powershell). The `Add-Migration` command scaffolds a migration to create the initial set of tables for the model. The `Update-Database` command creates the database and applies the new migration to it.

---

## Create, read, update & delete
## Use EF Core to access the database

* Open *Program.cs* and replace the contents with the following code:

[!code-csharp[Main](../../../../samples/core/GetStarted/Program.cs)]
[!code-csharp[Main](../../../../samples/core/GetStarted/Program.cs)]

## Run the app

Expand Down

This file was deleted.

55 changes: 0 additions & 55 deletions samples/core/GetStarted/Migrations/20190917222642_InitialCreate.cs

This file was deleted.

65 changes: 0 additions & 65 deletions samples/core/GetStarted/Migrations/BloggingContextModelSnapshot.cs

This file was deleted.

4 changes: 3 additions & 1 deletion samples/core/GetStarted/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ private static void Main()
{
using (var db = new BloggingContext())
{
// Note: This sample requires the database to be created before running.
// This will delete your database and recreate it each time the program is run.
db.Database.EnsureDeleted();
db.Database.EnsureCreated();

// Create
Console.WriteLine("Inserting a new blog");
Expand Down

0 comments on commit b4e1cdf

Please sign in to comment.