gordem
2021-09-23 10:57
采纳率: 100%
浏览 45

请教一个Linq To SQL的奇怪问题(Substring相关)

代码:

img


结果:
这里错误的结果,第一列:

img


正确的结果应该是这样:

img

原数据:

img

IQueryable<UserEmployeeResult> queryUser = from Emp in query                                                      
                                                   join User in DataContext2.Read.UserTable.Where(table => table.isAppUser == true) on Emp.SID equals User.EmployeeSID into JUser
                                                   from User in JUser.DefaultIfEmpty()
                                                   select new UserEmployeeResult
                                                   {
                                                       SID = Emp.SID,
                                                       Number = Emp.Number,
                                                       Name = Emp.Name,
                                                       PartNumber = Emp.PartNumber,
                                                       PartName = Emp.PartName,
                                                       SubjectNumber = Emp.SubjectNumber,
                                                       SubjectName = Emp.SubjectName,
                                                       Sex = Emp.Sex,
                                                       GroupNumber = Emp.GroupNumber,
                                                       GroupName = Emp.GroupName,
                                                       ClassNumber = Emp.ClassNumber,
                                                       ClassName = Emp.ClassName,
                                                       PartNo4 = Emp.PartNo4,
                                                       PartName4 = Emp.PartName4,
                                                       PartNo5 = Emp.PartNo5,
                                                       PartName5 = Emp.PartName5,
                                                       PartNo6 = Emp.PartNo6,
                                                       PartName6 = Emp.PartName6,
                                                       PartNo7 = Emp.PartNo7,
                                                       PartName7 = Emp.PartName7,
                                                       PartName0 = Emp.PartName0,
                                                       userID = User.AutoID,
                                                       userName = User.ID.Substring(1),//APP账号列,User.ID是原数据图里的ID列,正确数据应该是User.ID去最前面的#
                                                       hasAppUser = (User != null),
                                                       password = Emp.PassWord,
                                                       EmployeeAdmin = User.EmployeeAdmin,
                                                       ApproveAdmin = User.ApproveAdmin
                                                   };

为什么Substring(1)不应该是截取从索引1到最后的字符串么,怎么会去头去尾了??还是不定长的去尾(好像也定长,就字符串一半长度)

补充:结果图里APP账号一列的数据应该为数据图里ID一列去#,所以用的方法是User.ID.Substring(1),但对比数据可看出User.ID.Substring(1)截取的把ID后半也去掉了

1条回答 默认 最新

相关推荐 更多相似问题