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
Conditionally Required Property Using Data Annotations
How to Create a New Language for Use in Visual Studio
Memcached with Windows and .Net
How to Remove an Xml Element from File
What Happens in Beginprocessrequest()
Custom JSON Serialization for Each Item in Ienumerable
How to Register a .Net Com Dll with Regsvr32
Ef Data Context - Async/Await & Multithreading
How to Fill Forms and Submit with Webclient in C#
JSONconvert.Serializeobject Always Return {} in Xamarinforms
Disable Application Insights in Debug
Uploading and Downloading Large Files in ASP.NET Core 3.1
Sharing Violation Ioexception While Reading and Writing to File C#
Connecting to SQL Server with Visual Studio Express Editions
Add Custom Header in Httpwebrequest
Differencebetween Streamwriter.Flush() and Streamwriter.Close()