Using LINQ Queries As Data Sources

The LinqDataSource control supports only the basic LINQ clauses, such as select, where, and orderby. As I mentioned earlier, the LinqDataSource control will operate on any strongly typed IEnumerable sequence. One consequence of this is the ability to use the results from LINQ queries defined in code as the source for the data. Listing 18-13 shows a LINQ query defined in the Default.aspx.cs code-behind file.

Listing 18-13. Defining a LINQ query

using System; using System.Collections.Generic; using System.Linq; namespace WebApp {     public partial class Default : System.Web.UI.Page {         public IEnumerable<LinqWrapper> AthleteNames                 = new TrainingDataEntities().Events                      ...

Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.