/*______________________________________________________________ * G E T T I N G T O K N O W L I N Q Step 1 * * C# VERSION * Ron Kessler * 2/5/09 * * * _____________________________________________________________ */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { //---first create a new reference to our datacontext object AdventureworksDataContext dc = new AdventureworksDataContext(); //---now create a LINQ query string. Notice the use a var which creates // an anyonymous type. The eachproduct is a variable I created & is // created on the fly. Also, no type is defined! Category 18 has a bunch of data so I chose that. var products = from eachproduct in dc.Products where eachproduct.ProductCategoryID == 18 select eachproduct; //---now link up the grid to display our data GridView1.DataSource = products; GridView1.DataBind(); //make it so! } }