創建於2010年VS新的MVC 4 Internet應用程序我創建了一個「項目」模式,以及「ItemContext」類:無法獲得EF代碼首先要在MVC工作4
public class Item
{
public int ItemID { get; set; }
public string Name { get; set; }
}
public class ItemContext : DbContext
{
public DbSet<Item> Items { get; set; }
}
我建成該項目,然後用鼠標右鍵點擊「控制器」文件夾中,並嘗試添加一個新的控制器:
當我嘗試添加它,我收到以下錯誤,我不明白:
我有這個更大的問題,但我想我會嘗試沸騰下來這麼簡單,我可以看看我得到了什麼。我錯過了哪些步驟? 「Internet應用程序」項目已經有一個連接字符串,它也有一些會員相關的東西。
更新這是項目創建連接字符串:
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\aspnet.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True"
providerName="System.Data.SqlClient" />
嘗試將連接字符串名稱更改爲「ItemContext」。 – Eranga 2011-12-27 03:43:42
@Eranga做得很好,現在'ColumnAttribute'不明確,還有另一個與此相關的錯誤。 'ColumnAttribute'無法在解決方案中出現 – 2011-12-27 03:49:53
有可能在類的屬性上定義'Column'屬性。除Item Item之外是否還有模型類? – Eranga 2011-12-27 04:02:52