如何在这个Scenior中从表中获得最后记录

编程入门 行业动态 更新时间:2024-10-27 09:40:11
本文介绍了如何在这个Scenior中从表中获得最后记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有数据库表,其中我存储了同一个员工的多个状态,然后将这些记录输入到报告中,它工作正常,问题就在这里,当我在状态中添加一点状态添加为新记录,因为我想保存前一个,所以可以使用更新方法。现在我想得到该员工的最后一个记录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中从表中获得最后记录

本文发布于:2023-10-29 20:28:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1540660.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这个   Scenior

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!