2011-07-14 101 views
5

我下面一步步學習MVC和創建音樂商店,但由於某種原因,我不能讓下面的代碼工作..DbContext沒有編譯?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Data.Entity; 

namespace MvcMusicStore.Models 
{ 
    public class MusicStoreEntities : DbContext 
    { 
     public DbSet<Album> Albums { get; set; } 
     public DbSet<Genre> Genres { get; set; } 
    } 
} 

的的DbContext,DbSet和DbSet是給錯誤...

錯誤1類型或命名空間名稱「的DbContext」找不到(是否缺少using指令或程序集引用?)

爲什麼呢?

回答

5

您必須將對EntityFramework.dll部件的參考添加到您的項目中。最簡單的方法是安裝相應的NuGet package。如果您已安裝ASP.NET MVC 3 Tools Update,則在創建新項目時默認引用此NuGet包。如果沒有,只需安裝它。