我正在尝试使用Entity Framework 6从SQL Server数据库返回两个结果集。我想通过运行两个Linq to Entity查询来尝试,使用一个单独的DBContext。我的问题是,使用单个DBContext是否只会有一次数据库连接请求。我认为是这样,但我不确定。
class RequestRefLists
{
public List<Employee> EmployeeList {get;set;}
public List<Dept> 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 = (List<Employee>)queryResult1.ToList();
var queryResult2 = from d in context.Departments
select d;
ReqRefLists.DeptList = (List<Dept>)queryResult2.ToList();
}
return ReqRefLists;
}