public List<User> Getdata()
{
using (var context =new huntableEntities())
{
IQueryable<User> userrecords = (context.Users.Where(x => x.RecuiteReferalId == 24));
userrecords.ToList().ForEach(u =>
{
u.CurrentCompany =
u.EmploymentHistories.Where(
e => e.IsCurrent && e.MasterCompany != null).Select(
e => e.MasterCompany.Description).FirstOrDefault();
u.CurrentPosition =
u.EmploymentHistories.Where(
e => e.IsCurrent && !string.IsNullOrEmpty(e.JobTitle)).
Select(e => e.JobTitle).FirstOrDefault();
});
return userrecords.AsEnumerable().ToList();
}
}
我收到了object context disposed
at return 声明
我尝试通过查询和方法IEnumerable
,但结果是一样的。我还尝试将延迟加载设置为 false。
猜猜我哪里出错了?