I am developing a realtor's portal for my semester end project and I wanted to generate a list of my listings where the listedByID is equal to a session which is created when the user is logged in. here is the code
public ActionResult Index()
{
if ((string)Session["Role"] != "Private Seller")
{
return RedirectToAction("Login", "Account");
}
var data = db.tbl_listings.Where(x => x.l_listedByID == (int)Session["uID"]);
return View(data.ToList());
}
The problem is it is throwing this exception:
LINQ to Entities does not recognize the method 'System.Object get_Item(System.String)' method, and this method cannot be translated into a store expression.
I have tried this as well:
public ActionResult Index()
{
if ((string)Session["Role"] != "Private Seller")
{
return RedirectToAction("Login", "Account");
}
var data = db.tbl_listings.Where(x => x.l_listedByID == (int)Session["uID"]).ToList();
return View(data);
}
Any help would be appreciated, I am lost and the problem seems to be in the controller only. The problem arises when the code hits the "ToList()" method.