Skip to content

Commit 13e1f10

Browse files
authored
QuickGrid scaffolding dB context remarks (#34402)
1 parent 0a458a5 commit 13e1f10

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

aspnetcore/blazor/components/quickgrid.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,18 @@ With the **Add New Scaffold Item** dialog open to **Installed** > **Common** > *
420420

421421
Complete the **Add Razor Components using Entity Framework (CRUD)** dialog:
422422

423+
<!-- UPDATE 10.0 Keep an eye on https://github.com/dotnet/Scaffolding/issues/3131
424+
for a scaffolding update that makes the scaffolder a little
425+
smarter about suggesting an existing dB context that has a
426+
factory provider. If the scaffolder can do that, this instruction
427+
can be lightened up to just select ANY one from the list of
428+
existing providers or create a new one. -->
429+
423430
* The **Template** dropdown list includes other templates for specifically creating create, edit, delete, details, and list components. This dropdown list comes in handy when you only need to create a specific type of component scaffolded to a model class. Leave the **Template** dropdown list set to **CRUD** to scaffold a full set of components.
424431
* In the **Model class** dropdown list, select the model class. A folder is created for the generated components from the model name (if the model class is named `Movie`, the folder is automatically named `MoviePages`).
425-
* For **DbContext class**, select an existing database context or select the **+** (plus sign) button and **Add Data Context** modal dialog to add a new database context.
432+
* For **DbContext class**, take either of the following approaches:
433+
* Select an existing <xref:Microsoft.EntityFrameworkCore.DbContext> class that you know has a factory provider registration (<xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContextFactory%2A>).
434+
* Select the **+** (plus sign) button and use the **Add Data Context** modal dialog to supply a new <xref:Microsoft.EntityFrameworkCore.DbContext> class name, which registers the class with a factory provider instead of using the context type directly as a service registration.
426435
* After the model dialog closes, the **Database provider** dropdown list defaults to **SQL Server**. You can select the appropriate provider for the database that you're using. The options include SQL Server, SQLite, PostgreSQL, and Azure Cosmos DB.
427436
* Select **Add**.
428437

@@ -468,7 +477,7 @@ The following table explains the ASP.NET Core code generator options in the prec
468477
Option | Placeholder | Description
469478
------------- | -------------------- | ---
470479
`-dbProvider` | `{PROVIDER}` | Database provider to use. Options include `sqlserver` (default), `sqlite`, `cosmos`, `postgres`.
471-
`-dc` | `{DB CONTEXT CLASS}` | The <xref:Microsoft.EntityFrameworkCore.DbContext> class to use, including the namespace.
480+
`-dc` | `{DB CONTEXT CLASS}` | The <xref:Microsoft.EntityFrameworkCore.DbContext> class to use, including the namespace. To make sure that a <xref:Microsoft.EntityFrameworkCore.DbContext> class is registered in the app's services with a factory provider (<xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContextFactory%2A>), either use an existing <xref:Microsoft.EntityFrameworkCore.DbContext> class that you know has a factory provider registration or supply a new <xref:Microsoft.EntityFrameworkCore.DbContext> class.
472481
`-m` | `{MODEL}` | The name of the model class.
473482
`-outDir` | `{PATH}` | The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (if the model class is named `Movie`, the folder is automatically named `MoviePages`). The path is typically either `Components/Pages` for a Blazor Web App or `Pages` for a standalone Blazor WebAssembly app.
474483

@@ -517,7 +526,7 @@ The following table explains the ASP.NET Core code generator options in the prec
517526
Option | Placeholder | Description
518527
------------- | -------------------- | ---
519528
`-dbProvider` | `{PROVIDER}` | Database provider to use. Options include `sqlserver` (default), `sqlite`, `cosmos`, `postgres`.
520-
`-dc` | `{DB CONTEXT CLASS}` | The <xref:Microsoft.EntityFrameworkCore.DbContext> class to use, including the namespace.
529+
`-dc` | `{DB CONTEXT CLASS}` | The <xref:Microsoft.EntityFrameworkCore.DbContext> class to use, including the namespace. To make sure that a <xref:Microsoft.EntityFrameworkCore.DbContext> class is registered in the app's services with a factory provider (<xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContextFactory%2A>), either use an existing <xref:Microsoft.EntityFrameworkCore.DbContext> class that you know has a factory provider registration or supply a new <xref:Microsoft.EntityFrameworkCore.DbContext> class.
521530
`-m` | `{MODEL}` | The name of the model class.
522531
`-outDir` | `{PATH}` | The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (if the model class is named `Movie`, the folder is automatically named `MoviePages`). The path is typically either `Components/Pages` for a Blazor Web App or `Pages` for a standalone Blazor WebAssembly app.
523532

0 commit comments

Comments
 (0)