How to use a where clause in MVC ef
asp.net-mvc, entity-framework
Solution
public ActionResult Index(int id)
{
var drafts = db.Drafts.Where(d => d.PublicationId == id).ToList();
return View(drafts);
}
or if you wanna single draft (coz the id is usually unique):
public ActionResult Index(int id)
{
var draft = db.Drafts.SingleOrDefault(d => d.PublicationId == id);
return View(draft);
}
Problem
Using MVC EF, how would I filter results by a field other than the id? ``` return View(db.Drafts.Where(PublicationId=id)); ``` PublicationId is a column in the Drafts table. Any help is appreciated.