using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class LinqEntitiesSelect : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnExecutar_Click(object sender, EventArgs e)
    {
        BindDataGrid();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindDataGrid();
    }

    void BindDataGrid()
    {
        using (NorthwindDataContext db = new NorthwindDataContext())
        {
            var query = db.Products
            .Select(produto => new
            {
                IdProduto = produto.ProductID,
                NomeProduto = produto.ProductName
            });

            GridView1.DataSource = query;
            GridView1.DataBind();
        }
    }
}

