rustd / AspnetIdentitySample

476 stars 248 forks source link

ToList before Where in ToDoController #52

Open giuliohome opened 6 years ago

giuliohome commented 6 years ago

When you useToList you transform IQueryable in IEnumerable and so you wrongly select the user's todos in memory.

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

locoboeing commented 6 years ago

Change to this: return View(db.ToDoes.Where(todo => todo.User.Id == currentUser.Id).ToList());

azizsallam commented 6 years ago

thanks all