public static List <SalesOrderProductCategory> GetProductCategories()
 {
     using (var sc = new AdventureContext())
     {
         return((from prodCat in sc.ProductCategories
                 select new SalesOrderProductCategory
         {
             ProductCategoryID = prodCat.ProductCategoryID,
             Name = prodCat.Name
         }).ToList());
     }
 }
 public static List <SalesOrderProductSubcategory> GetProductSubcategories(int productCategoryID)
 {
     using (var sc = new AdventureContext())
     {
         return((from psc in sc.ProductSubcategories
                 where psc.ProductCategoryID == productCategoryID
                 select new SalesOrderProductSubcategory
         {
             ProductSubcategoryID = psc.ProductSubcategoryID,
             Name = psc.Name
         }).ToList());
     }
 }
 public static List <SalesOrderProduct> GetProducts(int productSubcategoryID)
 {
     using (var sc = new AdventureContext())
     {
         return((from p in sc.Products
                 where p.ProductSubcategoryID == productSubcategoryID
                 select new SalesOrderProduct
         {
             ProductID = p.ProductID,
             Name = p.Name,
             ListPrice = p.ListPrice
         }).ToList());
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId        = Request["salesOrderId"];
            long   salesOrderId = 0;

            if (!IsPostBack)
            {
                var query = new object();

                if (!string.IsNullOrEmpty(rawId) && long.TryParse(rawId, out salesOrderId))
                {
                    if (salesOrderId != 0)
                    {
                        hiddenSalesOrderId.Value = salesOrderId.ToString();

                        using (var sc = new AdventureContext())
                        {
                            query = (from order in sc.SalesOrderHeaders
                                     join detail in sc.SalesOrderDetails on order.SalesOrderID equals detail.SalesOrderID
                                     join product in sc.Products
                                     on detail.ProductID equals product.ProductID
                                     join productSubCat in sc.ProductSubcategories
                                     on product.ProductSubcategoryID equals productSubCat.ProductSubcategoryID
                                     where order.SalesOrderID == 44157 // salesOrderId
                                     select new
                            {
                                ContactLastName = order.Customer.Person.LastName,
                                ContactFirstName = order.Customer.Person.FirstName,
                                StreetAddress = order.Address.AddressLine1,
                                OrderNumber = order.SalesOrderNumber,
                                Total = order.TotalDue,
                                Product = order.SalesOrderDetails
                            }).ToList();
                        }
                    }
                }
            }
        }