iT邦幫忙

0

ASP.NET MVC 新增Controller時 DB設定出錯

  • 分享至 

  • xImage
public class HomeController : Controller
{
    dbShoppingCarEntities db = new dbShoppingCarEntities();
    public ActionResult Index()
    {
        var products = db.table_Product.OrderByDescending(m => m.Id).ToList();
        return View(products);
    }
}

dbShoppingCarEntities db = new dbShoppingCarEntities();這行出現以下錯誤
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0246?f1url=%3FappId%3Droslyn%26k%3Dk(CS0246)
通靈猜沒有安裝EntityFramework dll
WUcheap iT邦研究生 4 級 ‧ 2023-12-12 17:29:08 檢舉
沒有using Entity
wdchiang iT邦新手 2 級 ‧ 2023-12-13 11:17:51 檢舉
最好建立 DAL (Data Access Layer),不要在 Controller 直接 access db,

https://learn.microsoft.com/zh-tw/aspnet/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答