public List <Model.Stack> StackSer(DateTime currtime, DateTime begtime) { var res = dal.QueryWhere(s => s.DateTime >= begtime && s.DateTime <= currtime).GroupBy(g => new { g.StationID, g.EquipID }).Select(f => new { staid = f.Key.StationID, equid = f.Key.EquipID, upi = Math.Round((decimal)f.Average(u => u.UPI), 3) }); List <Model.Stack> stackres = new List <Model.Stack>(); int count = 1; // Regex.Replace(item.equipId, "[A-Z0]", "") + "#" foreach (var item in res) { Model.Stack stack = new Model.Stack() { Number = item.upi, Str = count.ToString() + "#" }; count++; stackres.Add(stack); } return(stackres); }