Example #1
0
 /// <summary>
 /// IQueryable of all Products
 /// </summary>
 /// <returns></returns>
 public IQueryable<Product> GetProducts()
 {
     var dataContext = new NorthwindEntities();
     var products = from p in dataContext.Products
                    select p;
     return products;
 }
        public void Fill()
        {
            var dataContext = new NorthwindEntities();

            Categories = dataContext
                            .Categories
                            .Select(a =>
                                new
                                {
                                    a.CategoryName,
                                    a.CategoryID
                                }
                            )
                            .ToList()
                            .Select(a =>
                                new SelectListItem
                                {
                                    Text = a.CategoryName,
                                    Value = a.CategoryID.ToString(),
                                    Selected = a.CategoryID == SelectedCategoryID
                                }).ToList();

            Suppliers = dataContext
                            .Suppliers.
                            Select(a =>
                                new
                                {
                                    a.CompanyName,
                                    a.SupplierID
                                }
                            )
                            .ToList()
                            .Select(a =>
                               new SelectListItem
                               {
                                   Text = a.CompanyName,
                                   Value = Convert.ToString(a.SupplierID),
                                   Selected = a.SupplierID == SelectedSupplierID
                               }).ToList();
        }