您可以使用Entity Framework扩展库.
有一个名为Future queries的功能
class RequestRefLists { public ListEmployeeList {get;set;} public List DeptList {get;set;} } public RequestRefLists GetRequestRefLists() { RequestRefLists ReqRefLists = new RequestRefLists(); using(var context= new BusinessDBContext) { var queryResult1 = from e in context.Employees select e; ReqRefLists.EmployeeList = queryResult1.Future(); var queryResult2 = from d in context.Departments select d; ReqRefLists.DeptList = queryResult2.Future(); } return ReqRefLists; }
您的查询将在任何集合的第一次枚举时执行延迟.
ExecuteFutureQueries从所有存储的IFutureQuery对象构建批处理查询.最后,使用查询结果更新所有IFutureQuery对象.