📜  LINQ 返回具有计数的唯一值列表 - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:20.539000             🧑  作者: Mango

代码示例1
// model
 public class orderviewmodel
    {
        public string OrderNumber { get; set; }
        public int Count { get; set; }
    }
    
 // BL
  public IList Read(string tmpC)
        {
            try
            {
                using (var entities = new UrEntities())
                {
                    return entities.Masters.Where(w => w.ContainerNumber.Equals(tmpC)).GroupBy(g => g.OrderNumber)
                        .Select(s => new orderviewmodel { OrderNumber = s.Key, Count = s.ToList().Count,  }).ToList();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }