linq 查到的list中只有一个记录 怎么不使用遍历取到这个记录中的某字段值

2025-04-29 17:37:27
推荐回答(1个)
回答1:

(
from staff in DB.SysStaffInfo
where staff.StaffCode == staffcode
select staff.staffName;
).First()
---------------
var list = from staff in DB.SysStaffInfo
where staff.StaffCode == staffcode
select staff;
if (list.Count() == 1)
{
string staffName= list.First().staffName;
}