Skip to content

Commit

Permalink
Corrections and clarifications (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
CamSoper committed Sep 9, 2024
1 parent c23b845 commit efed37b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/database/ef-core-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ Now that the migration service is configured, run the app to test the migrations
## Get the code

You can find the [completed sample app on GitHub](https://github.com/MicrosoftDocs/aspire-docs-samples/tree/solution/SupportTicketApi).

## More sample code

The [Aspire Shop](/samples/dotnet/aspire-samples/aspire-shop/) sample app uses this approach to apply migrations. See the `AspireShop.CatalogDbManager` project for the migration service implementation.
14 changes: 11 additions & 3 deletions docs/database/sql-server-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ In the _:::no-loc text="Program.cs":::_ file of the _AspireSQLEFCore_ project, a

This method accomplishes the following tasks:

- Registers a `TicketDbContext` with the DI container for connecting to the containerized Azure SQL Database.
- Registers a `TicketContext` with the DI container for connecting to the containerized Azure SQL Database.
- Automatically enable corresponding health checks, logging, and telemetry.

## Migrate and seed the database
## Create the database

While developing locally, you need to create a database inside the SQL Server container. Update the _:::no-loc text="Program.cs":::_ file with the following code to automatically run Entity Framework migrations during startup.
While developing locally, you need to create a database inside the SQL Server container. Update the _:::no-loc text="Program.cs":::_ file with the following code:

:::code language="csharp" source="snippets/tutorial/AspireSQLEFCore/AspireSQLEFCore/Program.cs" range="1-30" highlight="16-30":::

The preceding code:

- Checks if the app is running in a development environment.
- If it is, it retrieves the `TicketContext` service from the DI container and calls `Database.EnsureCreated()` to create the database if it doesn't already exist.

> [!NOTE]
> Note that `EnsureCreated()` is not suitable for production environments, and it only creates the database as defined in the context. It doesn't apply any migrations. For more information on Entity Framework Core migrations in .NET Aspire, see [Apply Entity Framework Core migrations in .NET Aspire](ef-core-migrations.md).
## Create the form

The app requires a form for the user to be able to submit support ticket information and save the entry to the database.
Expand Down

0 comments on commit efed37b

Please sign in to comment.