I have a method in my generic repository:
public IQueryable<T> Query<T>() where T : class, IEntity { return _context.Set<T>(); } This is method for getting user:
public User GetUser(string email) { return _repository.Query<User>().FirstOrDefault(u => u.Email == email); } Finally, I put the user to session:
AppSession.CurrentUser = UserService.GetUser(email); In my action I need to get the current user and get collection of objects Notifications (one-to-many):
AppSession.CurrentUser.Notifications.OfType<EmailNotification>().FirstOrDefault(); But, here I get the error:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection. I know that Notifications not loaded when I getting User from DB.
How to say EF to load Notifications objects? I know about Include, but I cannot use it in GetUser method.