Linq Distinct - Count

Linq distinct - Count

logins
.GroupBy(l => l.Date)
.Select(g => new
{
Date = g.Key,
Count = g.Select(l => l.Login).Distinct().Count()
});

Linq distinct count

Your question is not very clear, but I think this is what you want:

int totalCount = data.Count();
int distinctCount = data.Select(x => x.Id).Distinct().Count();
List<Item> result = new List<Item>
{
new Item() { Category = "1", Value = distinctCount },
new Item() { Category = "2", Value = totalCount - distinctCount },
};

LINQ query with distinct count

You need to group your results based on State and the Select count from the group like:

var query = ds.Tables[0].AsEnumerable()
.GroupBy(r => r.Field<string>("state"))
.Select(grp => new
{
state = grp.Key,
Count = grp.Count()
})
.OrderBy(o => o.state)
.ToList();

LINQ Select Distinct Count in Lambda form

Use this:

items.Select(i => i.Value).Distinct().Count()

Get the count of distinct elements from a list of lists using LINQ

You are almost there:

var test = student
.SelectMany(s => s.StudentAddresses) // get all addresses from students
.GroupBy(adr => adr.HouseZipCode) // group addresses by zip code
.Select(grp => new StudentModel { ZipCode= grp.Key, StudentNumbers = grp.Count() }) // count how many addresses have same zip code
.OrderBy(o => o.ZipCode)
.ToList();


Related Topics



Leave a reply



Submit