我有数据库表,其中我存储了同一个员工的多个状态,然后将这些记录输入到报告中,它工作正常,问题就在这里,当我在状态中添加一点状态添加为新记录,因为我想保存前一个,所以可以使用更新方法。现在我想得到该员工的最后一个记录c#代码在这里。
var incharge = _service.GetEmployeeStatusBySector_Id(sectorId)。其中(x = > x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x.IsDutiable == true ); foreach (EmployeeStatus Inchargesector in incharge) { var emp = _service.GetEmployee(Inchargesector.Employee_Id); foreach ( var empp in incharge) { dataset.InchargeSector.Rows.Add(Inchargesector.EmployeeShift_Id,emp.Name,emp.RankName,emp.CellNo); InchargeSector.Remove(empp); } }i无法使用它来产生问题 var incharge = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x = > x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x .IsDutiable == true )。last();
解决方案
In 最后(以及第一个和任何基于位置的选择)的任何场景都有任何意义,你必须定义一个ORDER,你没有做什么... 找到合适的列做排序比去看看如何在LINQ中使用它: http ://msdn.microsoft/en-us/library/vstudio/bb399396%28v=vs.100%29.aspx [ ^ ]
i have database table in which i am storing multiple status of same employee ,and then get these record in to the report,it work fine ,problem is here when i add a little bit change in the his status that status add as fresh record because i want to save previous one so can use update method.now i want to get last record of that employee c# code is here.
var incharge = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x => x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x.IsDutiable == true); foreach (EmployeeStatus Inchargesector in incharge) { var emp = _service.GetEmployee(Inchargesector.Employee_Id); foreach (var empp in incharge) { dataset.InchargeSector.Rows.Add(Inchargesector.EmployeeShift_Id, emp.Name, emp.RankName, emp.CellNo); InchargeSector.Remove(empp); } }i cant use it as follow that create problem
var incharge = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x => x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x.IsDutiable == true).last(); 解决方案 In any scenario to 'last' (and 'first' and any selection based on position) to have any meaning you have to define an ORDER, what you did not... Find the proper columns to do the ordering than go and read how to utilize it in LINQ: msdn.microsoft/en-us/library/vstudio/bb399396%28v=vs.100%29.aspx[^]更多推荐
如何在这个Scenior中从表中获得最后记录
发布评论