[EntityFramework CodeFirst easy to get started] (2) Example: Install CodeFirst development environment[EntityFramework CodeFirst easy to get started] (2) Example: Install CodeFirst development environment

table of Contents

related articles

[EntityFramework CodeFirst easy to get started] (1) Make the data persistence of the class easier

[EntityFramework CodeFirst easy to get started] (2) Example: Install CodeFirst development environment

[EntityFramework CodeFirst easy to get started] (3) Example: Create a new CodeFirst entity class

[EntityFramework CodeFirst easy to get started] (4) Example: Create a new CodeFirst database session [DbContext, DbSet]

[EntityFramework CodeFirst easy to get started] (5) Example: Use CodeFirst data session and entity classes

Contents of this chapter

1. Create a new VS console application project

2. Open the NuGet package of the management solution

3. Install the EntityFramework 6 plug-in to the project

4. Confirmation after installing EntityFramework 6


Software environment: Windows 10 + Microsoft Visual Studio 2019 + Sql Server 2017 Project type: console application (.Net Framework 4.7.2)

1. Create a new VS console application project

Create a new project In VS, create a new blank console application (.Net Framework 4.7.2) project, assuming the name is EntityFrameworkCodeFirst.

2. Open the NuGet package of the management solution

Select the following menu item in the standard menu: Tools\NuGet Package Manager\NuGet Packages for Management Solutions.

3. Install the EntityFramework 6 plug-in to the project

Select "Browse" in the window "Management Solution Package", enter "entity framework" in the search box, select "EntityFramework 6" from the search results, and then select the class library project created in the front from the project list on the right, and finally Select "Install". As shown in the figure.

During installation, click "OK" in the pop-up "Preview Changes" dialog box.

During installation, in the pop-up "Accept License" dialog box, click "I Accept".

4. Confirmation after installing EntityFramework 6

During the installation, the output dialog will show the progress of the installation. After the installation is complete, the output dialog box will display the words "Successfully installed "EntityFramework 6.4.4" to EntityFrameworkCodeFirst ", the current item in the project list changes from "not installed" to "installed" status, and displays the installed version (in the example Is EntityFramework version 6.4.4). As shown in the figure.

When EF is installed for the first time, the project configuration file App.config will add the content of <configSections> and <entityFramework> related nodes, as follows:

<?xml version="1.0" encoding="utf-8"?><configuration>  <configSections>    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />  </configSections>  <startup>    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />  </startup>  <entityFramework>    <providers>      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />    </providers>  </entityFramework></configuration>

When installing EF for the first time, add the following file packages.config with the following content:

<?xml version="1.0" encoding="utf-8"?><packages>  <package id="EntityFramework" version="6.4.4" targetFramework="net472" /></packages>

The following references will be added under the project: EntityFramework, EntityFramework.SqlServer, System.ComponentModel.DataAnnotations, as shown in the figure

PS: In the NuGet package of the management solution, you can uninstall the installed EntityFramework or replace the new version of EntityFramework.

the above