Example #1
0
        //public int ID { get; set; }
        //public string Name { get; set; }
        public static List <ComboCategory> GetCategories()
        {
            using (NorthwindDataContext db = new NorthwindDataContext())
            {
                var query = from c in db.Categories
                            select new ComboCategory()
                {
                    ID = c.CategoryID, Name = c.CategoryName
                };
                return(query.ToList());
            }
            //NorthwindDataContext db = new NorthwindDataContext();
            //var data = from c in db.Categories
            //           select c;

            //List<Category> retval = new List<Category>();
            //foreach (var item in data)
            //{
            //    Category newItem = new Category
            //    {
            //        ID = item.CategoryID,
            //        Name = item.CategoryName
            //    };
            //    retval.Add(newItem);
            //}
            //return retval;
            //return data.ToList();
        }
Example #2
0
 public static List <Supplier> GetSuppliers()
 {
     using (NorthwindDataContext db = new NorthwindDataContext())
     {
         var data = from s in db.Suppliers
                    select s;
         List <Supplier> retval = new List <Supplier>();
         foreach (var item in data)
         {
             Supplier newItem = new Supplier
             {
                 ID   = item.SupplierID,
                 Name = item.CompanyName
             };
             retval.Add(newItem);
         }
         return(retval);
     }
 }
Example #3
0
        public static List <Product> GetProducts()
        {
            NorthwindDataContext db = new NorthwindDataContext();
            var data = from p in db.Products
                       select p;

            List <Product> retval = new List <Product>();

            foreach (var item in data)
            {
                Product newItem = new Product
                {
                    ID         = item.ProductID,
                    Name       = item.ProductName,
                    Price      = item.UnitPrice ?? 0,
                    SupplierID = item.SupplierID
                };
                retval.Add(newItem);
            }

            return(retval);
        }