C# rax现在的建议。我感谢您的帮助,并将再次讨论此问题 private static List<BO.Employee> ListDirectReports(int mgrId) { IQueryable<B
rax现在的建议。我感谢您的帮助,并将再次讨论此问题C# rax现在的建议。我感谢您的帮助,并将再次讨论此问题 private static List<BO.Employee> ListDirectReports(int mgrId) { IQueryable<B,c#,linq,entity-framework,C#,Linq,Entity Framework,rax现在的建议。我感谢您的帮助,并将再次讨论此问题 private static List<BO.Employee> ListDirectReports(int mgrId) { IQueryable<BO.Employee> directRpts; using(var ctx = new Entities()) { directRpts = fro
private static List<BO.Employee> ListDirectReports(int mgrId)
{
IQueryable<BO.Employee> directRpts;
using(var ctx = new Entities())
{
directRpts =
from emp in ctx.Employee
join directRptHist in
(from employeeHistory in ctx.EmployeeHistory
.Where(h => h.DirectManagerEmployeeID == mgrId)
group employeeHistory by employeeHistory.EmployeeID into grp
let maxDt = grp.Max(g => g.DateLastUpdated) from history in grp
where history.DateLastUpdated == maxDt
select history)
on emp equals directRptHist.Employee
select emp;
}
return directRpts.ToList();
//IQueryable<BO.Employee> employees;
//using(var ctx = new Entities())
//{
// //function evaluation times out on this qry:
// // First make sure we're only looking at the current employee information
// IQueryable<BO.EmployeeHistory> currentEntries =
// from eh in ctx.EmployeeHistory
// group eh by eh.EmployeeID into grp
// select grp.OrderBy(eh => eh.DateLastUpdated).FirstOrDefault();
// // Now filter by the manager's ID
// var dirRpts = currentEntries
// .Where(eh => eh.DirectManagerEmployeeID == mgrId);
// // This would be ideal, assuming your entity associations are set up right
// employees = dirRpts.Select(eh => eh.Employee).Distinct();
// //// If the above won't work, this is the next-best thing
// //var employees2 = ctx.Employee.Where(
// // emp => directRpts.Any(
// // eh => eh.EmployeeId == emp.EmployeeId));
//}
//return employees.ToList();
}
私有静态列表ListDirectReports(int-mgrId)
{
易读目录;
使用(var ctx=new Entities())
{
directRpts=
来自ctx的emp。员工
将directRptHist加入
(来自ctx.employeeHistory中的employeeHistory
.Where(h=>h.DirectManagerEmployeeID==mgrId)
按employeeHistory.EmployeeID将employeeHistory分组到grp中
让maxDt=grp.Max(g=>g.DateLastUpdate)来自grp中的历史记录
其中history.DateLastUpdated==maxDt
选择历史记录)
在emp上等于directrphist.Employee
选择emp;
}
返回directRpts.ToList();
//优秀员工;
//使用(var ctx=new Entities())
//{
////此qry上的函数求值超时:
////首先确保我们只查看当前的员工信息
//IQueryable currentEntries=
//来自ctx.EmployeeHistory中的裕利安怡
//由eh.EmployeeID将eh分组到grp中
//选择grp.OrderBy(eh=>eh.DateLastUpdated.FirstOrDefault();
////现在按经理的ID进行筛选
//var dirRpts=currentEntries
//.Where(eh=>eh.DirectManagerEmployeeID==mgrId);
////假设您的实体关联设置正确,这将是理想的
//employees=dirRpts.Select(eh=>eh.Employee.Distinct();
/////如果上述方法不起作用,这是下一个最好的方法
////var employees2=ctx.Employee.Where(
////emp=>directRpts.Any(
////eh=>eh.EmployeeId==emp.EmployeeId));
//}
//return employees.ToList();
}
private List<BO.Employee> ListDirectReports(int mgrId)
{
using(var ctx = new Entities())
{
var directRptIDList =
from employeeHistory in ctx.EmployeeHistory
.Where(h => h.DirectManagerEmployeeID == mgrId)
group employeeHistory by employeeHistory.EmployeeID into grp
let maxDt = grp.Max(g => g.DateLastUpdated) from history in grp
where history.DateLastUpdated == maxDt
select history;
var directRpts =
from emp in ctx.Employee
join directRptHist in directRptIDList
on emp equals directRptHist.Employee
select emp;
}
return directRpts.ToList();
}
private List<BO.Employee> ListDirectReports(int mgrId)
{
using(var ctx = new Entities())
{
// First make sure we're only looking at the current employee information
var currentEntries =
from eh in ctx.EmployeeHistory
group employeeHistory by employeeHistory.EmployeeID into grp
select grp.OrderBy(eh => eh.DateLastUpdated).FirstOrDefault();
// Now filter by the manager's ID
var directRpts = currentEntries
.Where(eh => eh.DirectManagerEmployeeID == mgrId);
// This would be ideal, assuming your entity associations are set up right
var employees = directRpts.Select(eh => eh.Employee).Distinct();
// If the above won't work, this is the next-best thing
var employees2 = ctx.Employee.Where(
emp => directRpts.Any(
eh => eh.EmployeeId == emp.EmployeeId));
return employees.ToList();
}
}
private static List<BO.Employee> ListDirectReports(int mgrId)
{
IQueryable<BO.Employee> directRpts;
using(var ctx = new Entities())
{
directRpts =
from emp in ctx.Employee
join directRptHist in
(from employeeHistory in ctx.EmployeeHistory
.Where(h => h.DirectManagerEmployeeID == mgrId)
group employeeHistory by employeeHistory.EmployeeID into grp
let maxDt = grp.Max(g => g.DateLastUpdated) from history in grp
where history.DateLastUpdated == maxDt
select history)
on emp equals directRptHist.Employee
select emp;
}
return directRpts.ToList();
//IQueryable<BO.Employee> employees;
//using(var ctx = new Entities())
//{
// //function evaluation times out on this qry:
// // First make sure we're only looking at the current employee information
// IQueryable<BO.EmployeeHistory> currentEntries =
// from eh in ctx.EmployeeHistory
// group eh by eh.EmployeeID into grp
// select grp.OrderBy(eh => eh.DateLastUpdated).FirstOrDefault();
// // Now filter by the manager's ID
// var dirRpts = currentEntries
// .Where(eh => eh.DirectManagerEmployeeID == mgrId);
// // This would be ideal, assuming your entity associations are set up right
// employees = dirRpts.Select(eh => eh.Employee).Distinct();
// //// If the above won't work, this is the next-best thing
// //var employees2 = ctx.Employee.Where(
// // emp => directRpts.Any(
// // eh => eh.EmployeeId == emp.EmployeeId));
//}
//return employees.ToList();
}