Skip to content

Commit df8e003

Browse files
Rick-AndersonAndriySvyrydtdykstra
authored
ROPC warnings (#4849)
* ROPC warnings * ROPC warnings * ROPC warnings * ROPC warnings * ROPC warnings * work * work * work * work * work * work * work * work * work * work * work * work * Apply suggestions from code review Co-authored-by: Andriy Svyryd <[email protected]> Co-authored-by: Tom Dykstra <[email protected]> * fix warning erro * fix warning erro * fix warning erro * fix warning erro * fix warning erro * fix warning erro * fix warning erro --------- Co-authored-by: Andriy Svyryd <[email protected]> Co-authored-by: Tom Dykstra <[email protected]>
1 parent f6db772 commit df8e003

File tree

16 files changed

+102
-34
lines changed

16 files changed

+102
-34
lines changed

entity-framework/core/cli/powershell.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ The Package Manager Console (PMC) tools for Entity Framework Core perform design
1111

1212
If you aren't using Visual Studio, we recommend the [EF Core Command-line Tools](xref:core/cli/dotnet) instead. The .NET Core CLI tools are cross-platform and run inside a command prompt.
1313

14-
## Installing the tools
14+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
15+
16+
## Install the tools
1517

1618
Install the Package Manager Console tools by running the following command in **Package Manager Console**:
1719

@@ -53,7 +55,7 @@ SHORT DESCRIPTION
5355
<A list of available commands follows, omitted here.>
5456
```
5557

56-
## Using the tools
58+
## Use the tools
5759

5860
Before using the tools:
5961

@@ -215,7 +217,7 @@ Parameters:
215217

216218
| Parameter | Description |
217219
|:------------------------------------------|:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
218-
| <nobr>`-Connection <String>`</nobr> | The connection string to the database. For ASP.NET Core 2.x projects, the value can be *name=\<name of connection string>*. In that case the name comes from the configuration sources that are set up for the project. This is a positional parameter and is required. |
220+
| <nobr>`-Connection <String>`</nobr> | The connection string to the database. The value can be *name=\<name of connection string>*. In that case the name comes from the [configuration sources](xref:core/miscellaneous/connection-strings#aspnet-core) that are set up for the project. This is a positional parameter and is required. |
219221
| <nobr>`-Provider <String>`</nobr> | The provider to use. Typically this is the name of the NuGet package, for example: `Microsoft.EntityFrameworkCore.SqlServer`. This is a positional parameter and is required. |
220222
| <nobr>`-OutputDir <String>`</nobr> | The directory to put entity class files in. Paths are relative to the project directory. |
221223
| <nobr>`-ContextDir <String>`</nobr> | The directory to put the `DbContext` file in. Paths are relative to the project directory. |

entity-framework/core/dbcontext-configuration/index.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ uid: core/dbcontext-configuration/index
1010

1111
This article shows basic patterns for initialization and configuration of a <xref:Microsoft.EntityFrameworkCore.DbContext> instance.
1212

13+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
14+
1315
## The DbContext lifetime
1416

1517
The lifetime of a `DbContext` begins when the instance is created and ends when the instance is [disposed](/dotnet/standard/garbage-collection/unmanaged). A `DbContext` instance is designed to be used for a _single_ [unit-of-work](https://www.martinfowler.com/eaaCatalog/unitOfWork.html). This means that the lifetime of a `DbContext` instance is usually very short.
@@ -29,15 +31,17 @@ A typical unit-of-work when using Entity Framework Core (EF Core) involves:
2931

3032
> [!IMPORTANT]
3133
>
32-
> - It is very important to dispose the <xref:Microsoft.EntityFrameworkCore.DbContext> after use. This ensures both that any unmanaged resources are freed, and that any events or other hooks are unregistered so as to prevent memory leaks in case the instance remains referenced.
33-
> - [DbContext is **not thread-safe**](#avoiding-dbcontext-threading-issues). Do not share contexts between threads. Make sure to [await](/dotnet/csharp/language-reference/operators/await) all async calls before continuing to use the context instance.
34+
> - It is important to dispose the <xref:Microsoft.EntityFrameworkCore.DbContext> after use. This ensures any:
35+
> - Unmanaged resources are freed.
36+
> - Events or other hooks are unregistered. Unregistering prevents memory leaks when the instance remains referenced.
37+
> - [DbContext is **Not thread-safe**](#avoiding-dbcontext-threading-issues). Don't share contexts between threads. Make sure to [await](/dotnet/csharp/language-reference/operators/await) all async calls before continuing to use the context instance.
3438
> - An <xref:System.InvalidOperationException> thrown by EF Core code can put the context into an unrecoverable state. Such exceptions indicate a program error and are not designed to be recovered from.
3539
3640
## DbContext in dependency injection for ASP.NET Core
3741

3842
In many web applications, each HTTP request corresponds to a single unit-of-work. This makes tying the context lifetime to that of the request a good default for web applications.
3943

40-
ASP.NET Core applications are [configured using dependency injection](/aspnet/core/fundamentals/startup). EF Core can be added to this configuration using <xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext%2A> in the [`ConfigureServices`](/aspnet/core/fundamentals/startup#the-configureservices-method) method of `Startup.cs`. For example:
44+
ASP.NET Core applications are [configured using dependency injection](/aspnet/core/fundamentals/startup). EF Core can be added to this configuration using <xref:Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext%2A> in `Program.cs`. For example:
4145

4246
<!--
4347
public void ConfigureServices(IServiceCollection services)
@@ -48,9 +52,10 @@ ASP.NET Core applications are [configured using dependency injection](/aspnet/co
4852
options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection"));
4953
}
5054
-->
51-
[!code-csharp[ConfigureServices](../../../samples/core/Miscellaneous/ConfiguringDbContext/WebApp/Startup.cs?name=ConfigureServices)]
5255

53-
This example registers a `DbContext` subclass called `ApplicationDbContext` as a scoped service in the ASP.NET Core application service provider (a.k.a. the dependency injection container). The context is configured to use the SQL Server database provider and will read the connection string from ASP.NET Core configuration. It typically does not matter _where_ in `ConfigureServices` the call to `AddDbContext` is made.
56+
[!code-csharp[snippet_1](../../../samples/core/Miscellaneous/ConfiguringDbContext/WebApp9/Program9.cs?name=snippet_1)]
57+
58+
The preceding code registers `ApplicationDbContext`, a subclass of `DbContext`, as a scoped service in the ASP.NET Core app service provider. The service provider is also known as the dependency injection container. The context is configured to use the SQL Server database provider and reads the connection string from ASP.NET Core configuration.
5459

5560
The `ApplicationDbContext` class must expose a public constructor with a `DbContextOptions<ApplicationDbContext>` parameter. This is how context configuration from `AddDbContext` is passed to the `DbContext`. For example:
5661

@@ -63,9 +68,10 @@ The `ApplicationDbContext` class must expose a public constructor with a `DbCont
6368
}
6469
}
6570
-->
71+
6672
[!code-csharp[ApplicationDbContext](../../../samples/core/Miscellaneous/ConfiguringDbContext/WebApp/ApplicationDbContext.cs?name=ApplicationDbContext)]
6773

68-
`ApplicationDbContext` can then be used in ASP.NET Core controllers or other services through constructor injection. For example:
74+
`ApplicationDbContext` can be used in ASP.NET Core controllers or other services through constructor injection:
6975

7076
<!--
7177
public class MyController
@@ -82,13 +88,13 @@ The `ApplicationDbContext` class must expose a public constructor with a `DbCont
8288

8389
The final result is an `ApplicationDbContext` instance created for each request and passed to the controller to perform a unit-of-work before being disposed when the request ends.
8490

85-
Read further in this article to learn more about configuration options. In addition, see [App startup in ASP.NET Core](/aspnet/core/fundamentals/startup) and [Dependency injection in ASP.NET Core](/aspnet/core/fundamentals/dependency-injection) for more information on configuration and dependency injection in ASP.NET Core.
91+
Read further in this article to learn more about configuration options. See [Dependency injection in ASP.NET Core](/aspnet/core/fundamentals/dependency-injection) for more information.
8692

8793
<!-- See also [Using Dependency Injection](TODO) for advanced dependency injection configuration with EF Core. -->
8894

89-
## Simple DbContext initialization with 'new'
95+
## Basic DbContext initialization with 'new'
9096

91-
`DbContext` instances can be constructed in the normal .NET way, for example with `new` in C#. Configuration can be performed by overriding the `OnConfiguring` method, or by passing options to the constructor. For example:
97+
`DbContext` instances can be constructed with `new` in C#. Configuration can be performed by overriding the `OnConfiguring` method, or by passing options to the constructor. For example:
9298

9399
<!--
94100
public class ApplicationDbContext : DbContext
@@ -145,7 +151,7 @@ The `DbContextOptions` can be created and the constructor can be called explicit
145151
-->
146152
[!code-csharp[UseNewForWebApp](../../../samples/core/Miscellaneous/ConfiguringDbContext/WebApp/UseNewForWebApp.cs?name=UseNewForWebApp)]
147153

148-
## Using a DbContext factory (e.g. for Blazor)
154+
## Use a DbContext factory
149155

150156
Some application types (e.g. [ASP.NET Core Blazor](/aspnet/core/blazor/)) use dependency injection but do not create a service scope that aligns with the desired `DbContext` lifetime. Even where such an alignment does exist, the application may need to perform multiple units-of-work within this scope. For example, multiple units-of-work within a single HTTP request.
151157

entity-framework/core/includes/managed-identities-test-non-production.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ author: rick-anderson
44
ms.author: riande
55
ms.date: 10/23/2024
66
ms.topic: include
7+
title: an include file
78
---
89
> [!WARNING]
9-
> This article uses a local database that doesn't require the user to be authenticated. Production apps should use the most secure authentication flow available. For more information on authentication for deployed test and production apps, see [Secure authentication flows](xref:security/index#secure-authentication-flows).
10+
> This article uses a local database that doesn't require the user to be authenticated. Production apps should use the most secure authentication flow available. For more information on authentication for deployed test and production apps, see [Secure authentication flows](/aspnet/core/security/#secure-authentication-flows).

entity-framework/core/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ While EF Core is good at abstracting many programming details, there are some be
5050
* Find issues in the app that only show up when using a specific versions or edition of the database server.
5151
* Catch breaking changes when upgrading EF Core and other dependencies. For example, adding or upgrading frameworks like ASP.NET Core, OData, or AutoMapper. These dependencies can affect EF Core in unexpected ways.
5252
* Performance and stress testing with representative loads. The naïve usage of some features doesn't scale well. For example, multiple collections Includes, heavy use of lazy loading, conditional queries on non-indexed columns, massive updates and inserts with store-generated values, lack of concurrency handling, large models, inadequate cache policy.
53-
* Security review: For example, handling of connection strings and other secrets, database permissions for non-deployment operation, input validation for raw SQL, encryption for sensitive data.
53+
* Security review: For example, handling of connection strings and other secrets, database permissions for non-deployment operation, input validation for raw SQL, encryption for sensitive data. See [Secure authentication flows](/aspnet/core/security/#secure-authentication-flows) for secure configuration and authentication flow.
5454
* Make sure logging and diagnostics are sufficient and usable. For example, appropriate logging configuration, query tags, and Application Insights.
5555
* Error recovery. Prepare contingencies for common failure scenarios such as version rollback, fallback servers, scale-out and load balancing, DoS mitigation, and data backups.
5656
* Application deployment and migration. Plan out how migrations are going to be applied during deployment; doing it at application start can suffer from concurrency issues and requires higher permissions than necessary for normal operation. Use staging to facilitate recovery from fatal errors during migration. For more information, see [Applying Migrations](xref:core/managing-schemas/migrations/applying).

entity-framework/core/managing-schemas/migrations/applying.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,10 @@ Options:
222222
| `--no-color` | | Don't colorize output. |
223223
| `--prefix-output` | | Prefix output with level. |
224224

225-
The following example applies migrations to a local SQL Server instance using the specified username and password.
225+
The following example applies migrations to a local SQL Server instance using the specified username and credentials:
226226

227227
```powershell
228-
.\efbundle.exe --connection 'Data Source=(local)\MSSQLSERVER;Initial Catalog=Blogging;User ID=myUsername;Password=myPassword'
228+
.\efbundle.exe --connection 'Data Source=(local)\MSSQLSERVER;Initial Catalog=Blogging;User ID=myUsername;Password={;'$Credential;'here'}'
229229
```
230230

231231
> [!WARNING]

entity-framework/core/managing-schemas/scaffolding/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ uid: core/managing-schemas/scaffolding
77
---
88
# Scaffolding (Reverse Engineering)
99

10-
Reverse engineering is the process of scaffolding entity type classes and a `DbContext` class based on a database schema. It can be performed using the `Scaffold-DbContext` command of the EF Core Package Manager Console (PMC) tools or the `dotnet ef dbcontext scaffold` command of the .NET Command-line Interface (CLI) tools.
10+
Reverse engineering is the process of scaffolding entity type classes and a [DbContext](/dotnet/api/microsoft.entityframeworkcore.dbcontext) class based on a database schema. It can be performed using the `Scaffold-DbContext` command of the EF Core Package Manager Console (PMC) tools or the `dotnet ef dbcontext scaffold` command of the .NET Command-line Interface (CLI) tools.
1111

1212
> [!NOTE]
1313
> The scaffolding of a `DbContext` and entity types documented here is distinct from the [scaffolding of controllers in ASP.NET Core](/aspnet/mvc/overview/getting-started/introduction/adding-a-controller) using Visual Studio, which is not documented here.
@@ -27,9 +27,11 @@ Both the PMC and the .NET CLI commands have two required arguments: the connecti
2727

2828
### Connection string
2929

30-
The first argument to the command is a connection string to the database. The tools will use this connection string to read the database schema.
30+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
3131

32-
How you quote and escape the connection string depends on which shell you are using to execute the command; refer to your shell's documentation for more information. For example, PowerShell requires you to escape the `$` character, but not `\`.
32+
The first argument to the command is a connection string to the database. The tools use this connection string to read the database schema.
33+
34+
How the connection string is quoted and escaped depends on the shell that is used to run the command. Refer to the shell's documentation. For example, PowerShell requires escaping `$`, but not `\`.
3335

3436
The following example scaffolds entity types and a `DbContext` from the `Chinook` database located on the machine's SQL Server LocalDB instance, making use of the `Microsoft.EntityFrameworkCore.SqlServer` database provider.
3537

entity-framework/core/miscellaneous/multitenancy.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ uid: core/miscellaneous/multitenancy
1010

1111
Many line of business applications are designed to work with multiple customers. It is important to secure the data so that customer data isn't "leaked" or seen by other customers and potential competitors. These applications are classified as "multi-tenant" because each customer is considered a tenant of the application with their own set of data.
1212

13+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
14+
1315
> [!IMPORTANT]
1416
> This document provides examples and solutions "as is." These are not intended to be "best practices" but rather "working practices" for your consideration.
1517

entity-framework/ef6/fundamentals/configuring/config-file.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ ms.date: 10/23/2016
66
uid: ef6/fundamentals/configuring/config-file
77
---
88
# Configuration File Settings
9-
Entity Framework allows a number of settings to be specified from the configuration file. In general EF follows a ‘convention over configuration’ principle: all the settings discussed in this post have a default behavior, you only need to worry about changing the setting when the default no longer satisfies your requirements.
9+
Entity Framework allows a number of settings to be specified from the configuration file. In general EF follows a ‘convention over configuration’ principle: all the settings discussed in this post have a default behavior, you only need to worry about changing the setting when the default no longer satisfies your requirements.
10+
11+
## Configuration data guidelines
12+
13+
* Never store passwords or other sensitive data in configuration provider code or in plain text configuration files.
14+
* Don't use production secrets in development or test environments.
15+
* Specify secrets outside of the project so that they can't be accidentally committed to a source code repository.
16+
* Consider protecting the contents of the configuration file using [Protected Configuration](/dotnet/framework/data/adonet/connection-strings-and-configuration-files#encrypt-configuration-file-sections-using-protected-configuration).
17+
18+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
1019

1120
## A Code-Based Alternative
1221

entity-framework/ef6/fundamentals/configuring/connection-strings.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ ms.date: 10/23/2016
66
uid: ef6/fundamentals/configuring/connection-strings
77
---
88
# Connection strings and models
9-
This topic covers how Entity Framework discovers which database connection to use, and how you can change it. Models created with Code First and the EF Designer are both covered in this topic.
9+
This article covers how Entity Framework discovers which database connection to use, and how to change it. Models created with Code First and the EF Designer are covered.
1010

11-
Typically an Entity Framework application uses a class derived from DbContext. This derived class will call one of the constructors on the base DbContext class to control:
11+
[!INCLUDE [managed-identities-test-non-production](~/core/includes/managed-identities-test-non-production.md)]
1212

13-
- How the context will connect to a database — that is, how a connection string is found/used
14-
- Whether the context will use calculate a model using Code First or load a model created with the EF Designer
13+
14+
Typically an Entity Framework application uses a class derived from DbContext. This derived class calls one of the constructors on the base DbContext class to control:
15+
16+
- How the context connects to a database, that is, how a connection string is found and used.
17+
- Whether the context calculates a model using Code First or loads a model created with the EF Designer.
1518
- Additional advanced options
1619

1720
The following fragments show some of the ways the DbContext constructors can be used.

0 commit comments

Comments
 (0)