Open giuliohome opened 6 years ago
When you useToList you transform IQueryable in IEnumerable and so you wrongly select the user's todos in memory.
ToList
IQueryable
IEnumerable
public ActionResult Index() { var currentUser = manager.FindById(User.Identity.GetUserId()); return View(db.ToDoes.ToList().Where(todo => todo.User.Id == currentUser.Id)); }
You should delete the above said ToList in order to optimize the Where condition into the linq/EF autogenerated SQL
Where
Change to this: return View(db.ToDoes.Where(todo => todo.User.Id == currentUser.Id).ToList());
thanks all
When you use
ToList
you transformIQueryable
inIEnumerable
and so you wrongly select the user's todos in memory.You should delete the above said
ToList
in order to optimize theWhere
condition into the linq/EF autogenerated SQL