16

май

Entity Framework Core tools reference -.NET CLI. 9 minutes to read.In this articleThe command-line interface (CLI) tools for Entity Framework Core perform design-time development tasks. For example, they create, apply migrations, and generate code for a model based on an existing database.

The commands are an extension to the cross-platform command, which is part of the. These tools work with.NET Core projects.If you're using Visual Studio, we recommend the instead:.

Visual studio mac package manager console

Using Scaffolding to Create MVC Applications with Visual Studio Scaffolding is a great way of kick-starting model-view-controller (MVC) framework development. Visual Studio's MVC Scaffolding uses templates to generate the routine code that is common to all ASP.Net MVC builds, such as data access and Web API. We will code on Visual Studio Code because it's a IDE. Entity Framework Core and sqlite: getting started on macOS and Visual Studio Code. By code and will thus be created from scratch when the application runs.

They automatically work with the current project selected in the Package Manager Console without requiring that you manually switch directories. They automatically open files generated by a command after the command is completed.Installing the toolsThe installation procedure depends on project type and version:. EF Core 3.x. ASP.NET Core version 2.1 and later. EF Core 2.x.

EF Core 1.xEF Core 3.x.dotnet ef must be installed as a global or local tool. Most developers will install dotnet ef as a global tool with the following command: dotnet tool install -global dotnet-efYou can also use dotnet ef as local tool. To use it as a local tool, restore the dependencies of a project that declares it as a tooling dependency using a.Install the.Install the latest Microsoft.EntityFrameworkCore.Design package. Dotnet add package Microsoft.EntityFrameworkCore.DesignASP.NET Core 2.1+.Install the current. The SDK has to be installed even if you have the latest version of Visual Studio 2017.This is all that is needed for ASP.NET Core 2.1+ because the Microsoft.EntityFrameworkCore.Design package is included in the.EF Core 2.x (not ASP.NET Core)The dotnet ef commands are included in the.NET Core SDK, but to enable the commands you have to install the Microsoft.EntityFrameworkCore.Design package.Install the current. The SDK has to be installed even if you have the latest version of Visual Studio.Install the latest stable Microsoft.EntityFrameworkCore.Design package.

Dotnet add package Microsoft.EntityFrameworkCore.DesignEF Core 1.x.Install the.NET Core SDK version 2.1.200. Later versions are not compatible with CLI tools for EF Core 1.0 and 1.1.Configure the application to use the 2.1.200 SDK version by modifying its file. This file is normally included in the solution directory (one above the project).Edit the project file and add Microsoft.EntityFrameworkCore.Tools.DotNet as a DotNetCliToolReference item.

Specify the latest 1.x version, for example: 1.1.6. See the project file example at the end of this section.Install the latest 1.x version of the Microsoft.EntityFrameworkCore.Design package, for example: dotnet add package Microsoft.EntityFrameworkCore.Design -v 1.1.6With both package references added, the project file looks something like this: Exenetcoreapp1.1A package reference with PrivateAssets='All' isn't exposed to projects that reference this project. This restriction is especially useful for packages that are typically only used during development.Verify installationRun the following commands to verify that EF Core CLI tools are correctly installed: dotnet restoredotnet efThe output from the command identifies the version of the tools in use:/-/. ) / // / /Entity Framework Core.NET Command-line Tools 2.1.3-rtm-32065Using the toolsBefore using the tools, you might have to create a startup project or set the environment.

Target project and startup projectThe commands refer to a project and a startup project.The project is also known as the target project because it's where the commands add or remove files. By default, the project in the current directory is the target project. You can specify a different project as target project by using the -project option.The startup project is the one that the tools build and run. The tools have to execute application code at design time to get information about the project, such as the database connection string and the configuration of the model. By default, the project in the current directory is the startup project.

You can specify a different project as startup project by using the -startup-project option.The startup project and target project are often the same project. A typical scenario where they are separate projects is when:. The EF Core context and entity classes are in a.NET Core class library. A.NET Core console app or web app references the class library.It's also possible to.

Other target frameworksThe CLI tools work with.NET Core projects and.NET Framework projects. Apps that have the EF Core model in a.NET Standard class library might not have a.NET Core or.NET Framework project.

For example, this is true of Xamarin and Universal Windows Platform apps. In such cases, you can create a.NET Core console app project whose only purpose is to act as startup project for the tools. The project can be a dummy project with no real code — it is only needed to provide a target for the tooling.Why is a dummy project required?

As mentioned earlier, the tools have to execute application code at design time. To do that, they need to use the.NET Core runtime. When the EF Core model is in a project that targets.NET Core or.NET Framework, the EF Core tools borrow the runtime from the project. They can't do that if the EF Core model is in a.NET Standard class library. The.NET Standard is not an actual.NET implementation; it's a specification of a set of APIs that.NET implementations must support. Therefore.NET Standard is not sufficient for the EF Core tools to execute application code.

The dummy project you create to use as startup project provides a concrete target platform into which the tools can load the.NET Standard class library. ASP.NET Core environmentTo specify the environment for ASP.NET Core projects, set the ASPNETCOREENVIRONMENT environment variable before running commands. Common optionsOptionDescription-jsonShow JSON output.-c-context The DbContext class to use. Class name only or fully qualified with namespaces. If this option is omitted, EF Core will find the context class. If there are multiple context classes, this option is required.-p-project Relative path to the project folder of the target project. Default value is the current folder.-s-startup-project Relative path to the project folder of the startup project.

Default value is the current folder.-framework The for the. Use when the project file specifies multiple target frameworks, and you want to select one of them.-configuration The build configuration, for example: Debug or Release.-runtime The identifier of the target runtime to restore packages for. For a list of Runtime Identifiers (RIDs), see the.-h-helpShow help information.-v-verboseShow verbose output.-no-colorDon't colorize output.-prefix-outputPrefix output with level.dotnet ef database dropDrops the database.Options:OptionDescription-f-forceDon't confirm.-dry-runShow which database would be dropped, but don't drop it.dotnet ef database updateUpdates the database to the last migration or to a specified migration.Arguments: ArgumentDescriptionThe target migration. Migrations may be identified by name or by ID.

The number 0 is a special case that means before the first migration and causes all migrations to be reverted. If no migration is specified, the command defaults to the last migration.Options:OptionDescription-connection The connection string to the database. Defaults to the one specified in AddDbContext or OnConfiguring.The following examples update the database to a specified migration. Microsoft onenote for mac review rating pcmag.com. The first uses the migration name and the second uses the migration ID and a specified connection: dotnet ef database update InitialCreatedotnet ef database update 5021InitialCreate -connection yourconnectionstringdotnet ef dbcontext infoGets information about a DbContext type. Dotnet ef dbcontext listLists available DbContext types. Dotnet ef dbcontext scaffoldGenerates code for a DbContext and entity types for a database.

In order for this command to generate an entity type, the database table must have a primary key.Arguments: ArgumentDescriptionThe connection string to the database. For ASP.NET Core 2.x projects, the value can be name=.

In that case the name comes from the configuration sources that are set up for the project.The provider to use. Typically this is the name of the NuGet package, for example: Microsoft.EntityFrameworkCore.SqlServer.Options:OptionDescription-d-data-annotationsUse attributes to configure the model (where possible). If this option is omitted, only the fluent API is used.-c-context The name of the DbContext class to generate.-context-dir The directory to put the DbContext class file in. Paths are relative to the project directory. Namespaces are derived from the folder names.-context-namespace The namespace to use for the generated DbContext class.

Note: overrides -namespace.-f-forceOverwrite existing files.-o-output-dir The directory to put entity class files in. Paths are relative to the project directory.-n-namespace The namespace to use for all generated classes.

Defaults to generated from the root namespace and the output directory.-schema.The schemas of tables to generate entity types for. To specify multiple schemas, repeat -schema for each one.

1Intro Featuring –1:472Tha Block Is Hot Vocals Chorus –,4:123Loud Pipes Featuring –,5:144Whatcha Wanna Do3:505Kisha Featuring – Vocals Additional –4:176High Beamin' Featuring –4:097Lights Off4:068F. Tha World4:469Remember Me Featuring –3:5310Respect Us Featuring –5:0111Drop It Like It's Hot Featuring –,5:2312Young Playa Featuring –3:4713Enemy Turf Featuring –4:1914Not Like Me Featuring – Featuring Uncredited –,.4:0315Come On Featuring –3:3516Up To Me Vocals Additional, Chorus –4:3117You Want War Featuring –3:25. Tha block is hot album free download.

If this option is omitted, all schemas are included.-t-table.The tables to generate entity types for. To specify multiple tables, repeat -t or -table for each one. If this option is omitted, all tables are included.-use-database-namesUse table and column names exactly as they appear in the database. If this option is omitted, database names are changed to more closely conform to C# name style conventions.The following example scaffolds all schemas and tables and puts the new files in the Models folder.

Popular Posts