Entity Framework Core 2.1: Tools – Get-DbContext

This command is used to obtain information regarding the Data Context. This information is: The name of the provider, the name of the database, the name of the server, and if certain options are activated. An example of these options is the SensitiveDataLogging, which we have used to allow us to see the value of the variables in the logs.

In the dotnet CLI , this command is as follows:

dotnet ef dbcontext info

We can highlight the following options of this command:

  • Context: The data context to be used
  • Project: The project to be used
  • Json: Shows the information in JSON format. This option is only available for the dotnet CLI.

Examples

Basic use: For its basic use, we can use this command passing as an argument the name of the Data Context of which we want information. If we assume that our Data Context has the name ApplicationDbContext, then we can execute the following command in the Package Manager Console:

Get-DbContext -Context ApplicationDbContext

The equivalent command in the dotnet CLI is:

dotnet ef dbcontext info

————-

These are other commands we have seen so far:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s