在 LINQ c# 中按滚动文本排序
本文关键字:滚动 文本 排序 LINQ | 更新日期: 2023-09-27 18:27:33
我正在 LINQ 中编写一个查询,用于根据卷号获取所有学生的详细信息。滚动无字段是string
类型。但是我需要按卷订购,不作为int
.
var search = (from fs in Table1
join fsroll in Table2 on fs.tempId equals fsroll.tempId2
join ui in db.UserInfos on fsmuser.FormElementValue equals ui.UserInfoID.ToString()
select new UserViewModel
{
AvatarURL = ui.AvatarURL,
FirstName = ui.FirstName,
LastName = ui.LastName,
UserInfoID = ui.UserInfoID,
MobileNo = fsroll.FormElementValue,
loginStatus = ui.LoginStatus,
}).OrderBy(a => a.FirstName);
现在我按学生的名字字母顺序排列。但是我需要按rollno
对它们进行排序,这是文本字段。
那么,如何将其转换为int
,以便在rollno
中订购学生。
.OrderBy(a => Convert.ToInt32(a.rollno));
var search = (from fs in Table1
join fsroll in Table2 on fs.tempId equals fsroll.tempId2
join ui in db.UserInfos on fsmuser.FormElementValue equals ui.UserInfoID.ToString()
select new UserViewModel
{
AvatarURL = ui.AvatarURL,
FirstName = ui.FirstName,
LastName = ui.LastName,
UserInfoID = ui.UserInfoID,
MobileNo = fsroll.FormElementValue,
loginStatus = ui.LoginStatus,
rollNumber=fsroll.RollNumber
}).OrderBy(a => Convert.ToInt32(a.rollNumber));
或
var search = (from fs in Table1
join fsroll in Table2 on fs.tempId equals fsroll.tempId2
join ui in db.UserInfos on fsmuser.FormElementValue equals ui.UserInfoID.ToString()
orderby Convert.ToInt32(fsroll.rollNumber)
select new UserViewModel
{
AvatarURL = ui.AvatarURL,
FirstName = ui.FirstName,
LastName = ui.LastName,
UserInfoID = ui.UserInfoID,
MobileNo = fsroll.FormElementValue,
loginStatus = ui.LoginStatus
});