Answers for "linq command to find unique values in list"

C#
1

c# linq select only unique values from list

var uniq = allvalues.GroupBy(x => x.Id).Select(y=>y.First()).Distinct();
Posted by: Guest on November-17-2020
0

LINQ return list of unique values with 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;
            }
        }
Posted by: Guest on January-06-2022

Code answers related to "linq command to find unique values in list"

C# Answers by Framework

Browse Popular Code Answers by Language