2017-09-20 76 views
3

我越來越想添加遷移爲實體框架的核心,對代碼的第一個項目時的錯誤,這裏的細節...的EntityFramework核2.0 - 添加遷移錯誤「的EntityFramework包未安裝」

我已經創建了一個新的ASP.Net核心Web項目(VS 2017中的核心2.0)。它使用Microsoft.AspNetCore.All依賴,如下圖所示:

enter image description here

我期待利用實體框架的核心(我的理解是,所有的元數據有EF核心的依賴已經包含,如下圖所示,看起來是正確的):

enter image description here

我設置我的實體和上下文,我已經使用下面的代碼確保數據庫是建立。

範例模型

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; } 
} 

實施例上下文

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配置

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與該行的分貝conext在我的控制器:

public class DummyController : Controller 
{ 
    CityInfoContext _ctx; 

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

我可以看到該數據庫已成功創建 - 所有好爲止。

enter image description here

我想用這個命令來把我的分貝的快照: PM>添加遷移CityInfoInitialMigration

但得到的錯誤: 的的EntityFramework包裝上沒有安裝項目'CityInfo.API'。

enter image description here

有沒有人碰到這個纔來的?我明確嘗試添加EF包,但那也不起作用!

+0

它看起來像EF6 PMC命令正在運行...這是什麼'GET-模塊'說是加載? – bricelam

回答