對象我有一個方法,在我的通用倉庫:負載孩子EF5
public IQueryable<T> Query<T>() where T : class, IEntity
{
return _context.Set<T>();
}
這是獲取用戶的方法:
public User GetUser(string email)
{
return _repository.Query<User>().FirstOrDefault(u => u.Email == email);
}
最後,我把用戶會話:
AppSession.CurrentUser = UserService.GetUser(email);
在我的行動中,我需要獲得當前用戶並獲得對象集合Notifications
(一對多):
AppSession.CurrentUser.Notifications.OfType<EmailNotification>().FirstOrDefault();
但是,在這裏我得到的錯誤:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
我知道Notifications
當我從DB獲得User
沒有加載。
How to say EF加載Notifications
對象?我知道Include
,但我不能在GetUser
方法中使用它。