c# - ASP.NET MVC Entity Framework DB access in Controller -


i trying access db created display list. doing in controller. red underlining db part. saying "the name db not exist in current context." missing thing connect db in code?

using system.web; using system.web.mvc; using system.io; using system.web.helpers; using mis424assignments.models;  namespace mis424assignments.controllers {     [authorize (users="admin@wwu.edu")]     public class retailcontroller : controller     {         // get: retail         [allowanonymous]         public actionresult index()         {                              string sql = "select * product order newid()";                 list<product> productlist = db.product.sqlquery(sql).tolist();                 return view();         }     } } 

try

[authorize (users="admin@wwu.edu")] public class retailcontroller : controller {       private readonly retailstoreentities1 db;     public retailcontroller()     {         db = new retailstoreentities1();     }      // get: retail     [allowanonymous]     public actionresult index()     {                          string sql = "select * product order newid()";             list<product> productlist = db.product.sqlquery(sql).tolist();             return view();     } } 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -