LINQ Interview Question #16
What is a projection in LINQ?
LINQ Fundamentals, Syntax, IEnumerable & IQueryable Junior Beginner
Quick Interview Answer
Projection transforms each source element into another shape or value. Select is the primary projection operator, while SelectMany can flatten nested sequences.
Detailed Explanation
Projection transforms each source element into another shape or value. Select is the primary projection operator, while SelectMany can flatten nested sequences.
Projection is important for both in-memory code and database queries because it lets the application retrieve or create only the data shape it actually needs.
Code Example
var summaries = products
.Select(p => new
{
p.Id,
p.Name,
p.Price
});