[Original] PowerShell version problems and solutions when CodeFirst mode is used in EntityFramework Core,
I. Description:
CodeFirst mode is used when Entity Framework Core is used,
Run the following command on the PMC (nuget package management console) console in:
1 Install-Package Microsoft. EntityFrameworkCore. Tools2 3 Add-Migration Initial4 5 Update-DatabasePMC bash
Ii. Problems:
The PowerShell version is as follows:
The Entity Framework Core Package Manager Console Tools don't support PowerShell version 2.0. Upgrade to PowerShell version 3.0 or higher, restart Visual Studio, and try again.
Iii. solution:
(1) download version 4.0.
Https://www.microsoft.com/zh-CN/download/details.aspx? Id = 40855
2) install the downloaded package:
3) Open the vs pmc window and run the following command again:
4. automatically generated code:
Context code
1 using System; 2 3 using System. collections. generic; 4 5 using System. linq; 6 7 using System. threading. tasks; 8 9 using Microsoft. entityFrameworkCore; 10 11 12 13 namespace MvcMovie. models14 15 {16 17 public class MvcMovieContext: DbContext18 19 {20 21 public MvcMovieContext (DbContextOptions <MvcMovieContext> options) 22 23: base (options) 24 25 {26 27} 28 29 30 31 public DbSet <MvcMovie. models. movie> Movie {get; set;} 32 33} 34 35}C # code
Command Generation Code
1 using System; 2 3 using System. collections. generic; 4 5 using Microsoft. entityFrameworkCore. migrations; 6 7 using Microsoft. entityFrameworkCore. metadata; 8 9 10 11 namespace MvcMovie. migrations12 13 {14 15 public partial class Initial: Migration16 17 {18 19 protected override void Up (MigrationBuilder migrationBuilder) 20 21 {22 23 migrationBuilder. createTable (24 25 name: "Movie", 26 27 columns: table => new28 29 {30 31 ID = table. column <int> (nullable: false) 32 33. annotation ("SqlServer: ValueGenerationStrategy", SqlServerValueGenerationStrategy. identityColumn), 34 35 Genre = table. column <string> (nullable: true), 36 37 Price = table. column <decimal> (nullable: false), 38 39 ReleaseDate = table. column <DateTime> (nullable: false), 40 41 Title = table. column <string> (nullable: true) 42 43}, 44 45 constraints: table => 46 47 {48 49 table. primaryKey ("PK_Movie", x => x. ID); 50 51}); 52 53} 54 55 56 57 protected override void Down (MigrationBuilder migrationBuilder) 58 59 {60 61 migrationBuilder. dropTable (62 63 name: "Movie"); 64 65} 66 67} 68 69}C # code
Mon
Friday