c# linq select only unique values from list
var uniq = allvalues.GroupBy(x => x.Id).Select(y=>y.First()).Distinct();
c# linq select only unique values from list
var uniq = allvalues.GroupBy(x => x.Id).Select(y=>y.First()).Distinct();
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;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us