score:1
Accepted answer
// Get collection
var collection = _database.GetCollection<VehicleDataUpload>("Vehicles");
// Get first project that meets our identifier
var aggregation = collection
.AsQueryable()
// This will return an IEnumerable of Vehicles object
.Where(i => i.ProjectId.Equals("1234"))
// Assuming you want to return a plain list, you should use SelectMany
.SelectMany(v => v.VehicleEntries
// You group each list of VehicleEntries
.GroupBy(ve => ve.Data)
// For each group you return a new DailySummaryData object
.Select(g => new DailySummaryData() {
ProjectName = v.ProjectId,
Date = g.Key,
Passed = g.Sum(x => (x.VehicleStatus.Equals("PASSED") ? 1 : 0)),
Failed = g.Sum(x => (x.VehicleStatus.Equals("FAILED") ? 1 : 0))
})
return aggregation.ToList();
Source: stackoverflow.com
Related Query
- Aggregating Lists inside of a List of objects using LINQ
- List of EF objects to Dictionary of lists using linq
- search list objects inside strings using LINQ to SQL
- Add objects to a List nested inside a Dictionary using LINQ extensions
- Xml parse object inside of list of objects inside object using LINQ
- Using Linq to do: Compile a list of all lists within a list of objects
- Using linQ to group list of object into new lists of objects
- Return select objects and only desired subvalues from a list of lists using LINQ
- Creating sub lists with objects of the same attribute from a list using LINQ
- Merging lists of objects using linq while showing preference over a condition in one list
- Using linq to instantiate objects containing lists of other objects, where query criteria is on inner list
- Searching if value exists in a list of objects using Linq
- Using Linq to group a list of objects into a new grouped list of list of objects
- Using LINQ, select list of objects inside another list of objects
- Using LINQ to group a list of objects
- Using Linq select list inside list
- Change the property of objects in a List using LINQ
- Find child objects in list of parent objects using LINQ
- Union A List of Lists Using Linq
- Sort a list and all its nested objects using LINQ
- Using LINQ to merge a list of objects
- Using LINQ to Get Sum/ Average of a List with custom objects
- Using Linq query inside List<T>.AddRange to conditionally add elements from one list to another
- Using Linq and C#, trying to get two lists from a list of master items grouped by two inner lists
- compare lists and return common objects using LINQ
- How to convert list of objects with two fields to array with one of them using LINQ
- Using Linq to compare a list with a set of lists in C#
- Using Linq to group a list of objects that contains primitives data into a new grouped list of objects
- Linq To XML - Using XDocument and creating list of objects
- Query in returning Objects from List using LINQ
More Query from same tag
- Sql Select Statement Issue in order by
- whats the fastest way to write join in linq
- I need a LINQ expression to find an XElement where the element name and attributes match an input node
- LINQ IQueryable with group by and count
- Retrieve data in view sent from controller
- Loop Through LINQ Query Columns (Not rows)
- How to combine two columns from a database with LINQ?
- SQL Query -- Generate a 2 collections based on differences?
- Concatenate Property of a object in Collection.
- LINQ Query - Proper "Where" clause to select only children that meet a condition
- Cant use OrderBy with int[,] - c#
- Find frequencies of a specific property value in a list<object>
- Linq returns null when invoice does not contains any items
- Loading data from three related tables in ASP.NET Core using Entity Framwork Core in one-to-many relationship makes some data not displayed
- how to optimize linq query where Data is coming from two different databases?
- How to append unique numbers to a list of strings
- Linq to SQL for EntityFramework.Extensions Update() method with ?? operator
- How to use let to define a new set of data within a LINQ query?
- Creating a LINQ query that will include all entries from the current week excluding today and yestreday
- Preventing duplicate element access when reading an XML using LINQ
- Why Standard Extension Method on IEnumerables
- How to find total number of childs and Number of grand child levels under a hierarchical list parent in C#
- C# Find and edit single object on list
- Entity Framework + Model + 2 Tables + List
- Order by bigger of two Sql columns
- Using Generic with Func as a parameter
- Enumerating stored procedure result - The result of a query cannot be enumerated more than once
- Linq "Where In" subquery to filter data
- Linq get list of indexes matching a condition to filter another list against
- Values of type 'collection[Edm.String(Nullable=True,DefaultValue=,MaxLength=,Unicode=,FixedLength=)]' can not be converted to string