Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

C# list of unique values with group and counts

// model
 public class orderviewmodel
    {
        public string OrderNumber { get; set; }
        public int Count { get; set; }
    }
    
 // BL
  public IList<orderviewmodel> 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;
            }
        }
 
PREVIOUS NEXT
Tagged: #list #unique #values #group #counts
ADD COMMENT
Topic
Name
2+9 =