/*______________________________________________________ // LINQ 2: Using Calculations Ron Kessler 2/9/09 _______________________________________________________ */ //Make sure to look at the tables I use in my Object Designer and add them. //This form shows how to grab data, make sure it is not null and if so put in a //0 in that column. Also shows how to make a calculation in a column. //Introduces Lambda expressions & Nullable types //Step 2: Look at the paging.aspx form. Make it the Startup form remember! 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) { AdventureWorksDataContext dc = new AdventureWorksDataContext(); var products = from p in dc.Products where p.ProductCategory.Name == "Mountain Bikes" select new { Product_ID = p.ProductID, Product_Name = p.Name, Order_Count = p.SalesOrderDetails.Count, Total_Sales = String.Format("{0:n2}", p.SalesOrderDetails.Sum(s => (decimal?)s.OrderQty * (decimal?)s.UnitPrice) ?? 0) }; GridView1.DataSource = products; GridView1.DataBind(); } }