Aggregation. Linq to objects query?

Assuming Test implements IEnumerable q. Where(a => a. IsCorrect) .

Select(a => new { Question = q, Answer = a })).

Assuming Test implements IEnumerable and Question implements IEnumerable: var questionsWithCorrectAnswers = myTest . SelectMany(q => q. Where(a => a.

IsCorrect) . Select(a => new { Question = q, Answer = a })).

I havent got an access for Questions in Test. I can only get an enumerator. – Sergey Gavruk Sep 29 '10 at 16:39 1 @Sergey: Fixed.

– Timwi Sep 29 '10 at 16:50.

First off, your Questions and Answers are private. I'll assume you have a public accessor Questions and Answers, respectively. Try this: var results = from q in t.

Questions where q.Answers. Any(a=>a. IsCorrect) select new {Question = q, CorrectAnswers = q.Answers.

Where(a=>a. IsCorrect)}; You can now reference results. Question and results.CorrectAnswers.

You can also select a new Question where the Answers list contains only correct Answers.

The standard query operators are the methods that form the Language-Integrated Query (LINQ) pattern. Most of these methods operate on sequences, where a sequence is an object whose type implements the IEnumerable interface or the IQueryable interface. The standard query operators provide query capabilities including filtering, projection, aggregation, sorting and more.

There are two sets of LINQÂ standard query operators, one that operates on objects of type IEnumerable and the other that operates on objects of type IQueryable. The methods that make up each set are static members of the Enumerable and Queryable classes, respectively. They are defined as extension methods of the type that they operate on.

This means that they can be called by using either static method syntax or instance method syntax. In addition, several standard query operator methods operate on types other than those based on IEnumerable or IQueryable. The Enumerable type defines two such methods that both operate on objects of type IEnumerable.

These methods, Cast(IEnumerable) and OfType(IEnumerable), let you enable a non-parameterized, or non-generic, collection to be queried in the LINQ pattern. They do this by creating a strongly-typed collection of objects. The Queryable class defines two similar methods, Cast(IQueryable) and OfType(IQueryable), that operate on objects of type Queryable.

The standard query operators differ in the timing of their execution, depending on whether they return a singleton value or a sequence of values. Those methods that return a singleton value (for example, Average and Sum) execute immediately. Methods that return a sequence defer the query execution and return an enumerable object.

In the case of the methods that operate on in-memory collections, that is, those methods that extend IEnumerable, the returned enumerable object captures the arguments that were passed to the method. When that object is enumerated, the logic of the query operator is employed and the query results are returned. In contrast, methods that extend IQueryable do not implement any querying behavior, but build an expression tree that represents the query to be performed.

The query processing is handled by the source IQueryable object. Calls to query methods can be chained together in one query, which enables queries to become arbitrarily complex. The following code example demonstrates how the standard query operators can be used to obtain information about a sequence.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions