Aggregating Lists inside of a List of objects using LINQ
<p>As a follow up to <a href="https://stackoverflow.com/questions/34398502/how-can-i-aggregate-over-arrays-inside-documents-in-mongodb-and-get-counts-for-m">this question</a>, where I needed to aggregate over inner arrays in MongoDB, I am trying to accomplish the same task in LINQ.</p>

<p>I am close, as I have figured out how to aggregate over an individual item:</p>

<pre><code>// Get collection
var collection = _database.GetCollection&lt;VehicleDataUpload&gt;("Vehicles");

// Get first project that meets our identifier
var firstProject = collection.AsQueryable().Where(i =&gt; i.ProjectId.Equals("1234")).First();

// Get a list of DailySummaryData objects 
var aggregation = 
    from entry in firstProject.VehicleEntries
    group entry by entry.Data
    into result
    select new DailySummaryData() {
        ProjectName = firstProject.ProjectId,
        Date = result.FirstOrDefault().Date,
        Passed = result.Sum(x =&gt; (x.VehicleStatus.Equals("PASSED") ? 1 : 0)),
        Failed = result.Sum(x =&gt; (x.VehicleStatus.Equals("FAILED") ? 1 : 0))
    };

return aggregation.ToList();
</code></pre>

<p>However, I can't use <code>...First()</code> on the collection, because there might be multiple VehicleDataUploads for a project. How can I aggregate over all the lists inside the list of documents that are returned?</p>