使用linq拆分列表中的字符串值

Split a string value in list using linq

我有一个列值类似于“0000000385242160714132019116002239344.ACK”的列表,当绑定到列表时,我需要从该值(例如“239344”)中取出没有扩展名(.ack)的最后 6 位数字。 我还需要找到 Salary 字段的总和。

我的查询如下所示。

var result = from p in Context.A
                             join e in B on p.Id equals e.Id
                             join j in Context.C on e.CId equals j.CId
                             where (e.Date >= periodFrom && e.Date <= periodTo)
                             group new
                             {
                                 e,
                                 j
                             } by new
                             {
                                 j.J_Id,
                                 e.Date,
                                 e.Es_Id,
                                 e.FileName,
                                 j.Name,
                                 e.ACK_FileName,
                                 p.EmpSalaryId,
                                 p.Salary
                             } into g
                             orderby g.Key.CId, g.Key.Es_Id, g.Key.Date, g.Key.FileName
                             select new
                             {
                                 CorporateId = g.Key.CId,
                                 ProcessedDate = g.Key.Date,
                                 EstID = g.Key.Es_Id,
                                 FileName = g.Key.FileName,
                                 Name = g.Key.Name,
                                 ack = g.Key.ACK_FileName,
                                 EmpSalaryId = g.Key.EmpSalaryId,
                                 Salary=g.Key.Salary
                             };

var Abc=result.ToList();
var result = (from p in Context.A
             join e in B on p.Id equals e.Id
             join j in Context.C on e.CId equals j.CId
             where (e.Date >= periodFrom && e.Date <= periodTo)
             group new { e, j } by new
             {
                 j.J_Id,
                 e.Date,
                 e.Es_Id,
                 e.FileName,
                 j.Name,
                 ACK_FileName = e.ACK_FileName.Substring(e.ACK_FileName.IndexOf(".ACK") - 7, 11),
                 p.EmpSalaryId,
                 p.Salary
             } into g
             orderby g.Key.CId, g.Key.Es_Id, g.Key.Date, g.Key.FileName
             select new
             {
                 CorporateId = g.Key.CId,
                 ProcessedDate = g.Key.Date,
                 EstID = g.Key.Es_Id,
                 FileName = g.Key.FileName,
                 Name = g.Key.Name,
                 ack = g.Key.ACK_FileName,
                 EmpSalaryId = g.Key.EmpSalaryId,
                 Salary = g.Sum(item => item.Salary)
             }).ToList();