不幸的是,我正在维护一个系统,它没有考虑一旦系统拥有数百万条记录会发生什么。
我遇到的问题是当前编写代码的方式主要是 GetList 方法实际上从数据库中返回每条记录,并且过滤是在 getfull 方法中完成的。
我尝试通过将调整的 id 传递给 getlist 方法来更改此设置,但是当我尝试执行 .Where(a=>a.Id == journalid) 时出现此错误
无法将类型“System.Linq.IQueryable”隐式转换为“System.Data.Objects.ObjectQuery”
public Adjustment GetFull(int id) {
var result = GetList(id).FirstOrDefault(ja => ja.Id == id);
if(result == null) {
throw new InvalidOperationException(
String.Format(" Adjustment with Id={0} not found.", id)
);
}
return LoadFullActivities(result);
}
private IQueryable<Adjustment> GetList(int journalid) {
return GetList(journalid,"Original", "Activities",
"Original.Employee", "Original.Employee.EmployeeType",
"Original.Employee.WorkType", "Original.Employee.Department",
"Original.Activities", "Original.Status",
"Original.Approver", "Status");
}
private IQueryable<Adjustment> GetList(int journalid, params string[] includes) {
var tempResult = dataContext.AdjustmentSet;
foreach (var property in includes) {
tempResult = tempResult.Include(property).Where(a=>a.Id == journalid) ;
}
return tempResult;
}