O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

LINQ Projections

You probably remember from Chapter 1 that in relational database theory a projection is a query that returns a subset of the fields in a row. LINQ supports projections, too. They’re returned as a new type, called an ANONYMOUS TYPE, that complies with the syntax for anonymous types in your language.

Image

from s in context.Suppliers    select new {s.FirstName, s.Surname}

Image

From s in context.Suppliers    Select New With {s.FirstName, s.Surname}

You can also assign a name to the anonymous type. In C# this requires a let clause, but ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required