2017-09-20 3 views
3

Ich erhalte eine Fehlermeldung, wenn Migration für Entity Framework Core hinzufügen versuchen, zu einem Kodex Erstes Projekt, hier die Details ...EntityFramework Core 2.0 - Hinzufügen Migration Fehler „Das EntityFramework Paket nicht installiert ist“

Ich habe ein neues ASP.Net Core-Webprojekt erstellt (Core 2.0 in VS 2017). Seine die Microsoft.AspNetCore.All Abhängigkeit verwendet wird, wie folgt dar:

enter image description here

Ich suche das Entity Framework Core (mein Verständnis zu nutzen war, dass alle Metadaten die EF-Core Abhängigkeiten bereits enthalten waren, unten sieht richtig sein): meine Entitäten und Kontext, und ich habe sichergestellt

enter image description here

ich habe Setup die DB ist Setup mit dem folgenden Code.

Beispiel Modell

public class City 
{ 
    [Key] 
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 
    public int Id { get; set; } 

    [Required] 
    [MaxLength(50)] 
    public string Name { get; set; } 

    [MaxLength(200)] 
    public string Description { get; set; } 
} 

Beispiel Context

public class CityInfoContext : DbContext 
{ 
    public DbSet<City> Cities { get; set; } 
    public DbSet<PointOfInterest> PointsOfInterest { get; set; } 

    public CityInfoContext(DbContextOptions options) : base(options) 
    { 
     Database.EnsureCreated(); 
    } 
} 

Startup.cs Config

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddMvc() 
    .AddMvcOptions(options => { 
     options.OutputFormatters.Add(new XmlDataContractSerializerOutputFormatter()); 
    }) 
    .AddJsonOptions(options => { 
     if (options.SerializerSettings.ContractResolver != null) 
     { 
      var res = options.SerializerSettings.ContractResolver as DefaultContractResolver; 
      res.NamingStrategy = null; 
     } 
    }); 

    services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); 
    services.AddSingleton<IMailService, LocalMailService>(); 

    // Entity Framework services. 
    var connectionString = @"Server=(localdb)\mssqllocaldb;Database=CityInfoDB;Trusted_Connection=True;"; 
    services.AddDbContext<CityInfoContext>(options => options.UseSqlServer(connectionString)); 
} 

Ini tializing die db Conext mit dieser Linie in meinem Controller:

public class DummyController : Controller 
{ 
    CityInfoContext _ctx; 

    public DummyController(CityInfoContext ctx) 
    { 
     _ctx = ctx; 
    } 
} 

ich die db erfolgreich erstellt wird, sehen kann - alles so weit gut.

enter image description here

Ich möchte einen Schnappschuss von meiner db nehmen diesen Befehl: PM> Add-Migration CityInfoInitialMigration

Aber erhalten Sie den Fehler: Das EntityFramework Paket ist nicht auf Projekt installiert 'CityInfo.API'.

enter image description here

Hat über diese, bevor jemand kam? Ich habe explizit versucht, die EF-Pakete hinzuzufügen, aber das hat auch nicht funktioniert! Verwendung der Befehlszeilenschnittstelle

+0

Es sieht aus wie die EF6 PMC Befehle ausgeführt werden ... Was bedeutet 'Get-Module 'Say ist geladen? – bricelam

Antwort

Verwandte Themen