2016-12-02 85 views
1

我建立一個項目在VS 2015年,我試圖啓用的遷移創建一個使用實體框架的數據庫,但我得到一個錯誤:的Visual Studio - 啓用 - 遷移問題

Cannot determine a valid start-up project. Using project 'Data Manager' instead. Your configuration file and working directory may not be set as expected. Use the -StartUpProjectName parameter to set one explicitly. Use the -Verbose switch for more information. No context type was found in the assembly 'Data Manager'.

我發現幾條線索和潛在的解決方案,但沒有運氣。到目前爲止,我曾嘗試:

  1. 重建方案和重置VS

  2. 我證實,默認的項目設置爲「DataManager的」與 既是「nuget.org」和「全部」包源

  3. 啓用的遷移-ProjectName的DataManager

  4. 我重新安裝與條命令:安裝,包裝的EntityFramework -IncludePrerelea se

我在想什麼?

+0

可以顯示上下文類代碼? – Sampath

+0

您是否嘗試過從nuget控制檯中的「默認項目」組合框中選擇包含您的dbcontext的項目? – Den

+0

所以它看起來像我缺少上下文......我不知道上下文類代碼將在哪裏,如果我錯過了它,應該在它裏面......假設它應該是圍繞「dbcontext」的東西。我已經看到了教程中的「Identity Models」模型,下面有一個applicaitondbcontext類,但我認爲它是自動生成的......我將轉到他們的github,看看我是否可以手工複製它,然後嘗試遷移 – user2653814

回答

0

看起來你沒有上Data Manager項目的上下文類。你必須指定它,如下所示。

namespace MigrationsAutomaticDemo 
    { 
     public class YourContext : DbContext 
     { 
      public DbSet<Blog> Blogs { get; set; } 
     } 

     public class Blog 
     { 
      public int BlogId { get; set; } 
      public string Name { get; set; } 
     } 
    } 

希望它會在那之後工作。

你可以閱讀更多關於它在這裏:Automatic Code First Migrations

+0

對此有何反饋? – Sampath