Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting started app #3079

Merged
merged 5 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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