public byte[] GetProductImage(int productId) { AdventureWorksDataContext db = new AdventureWorksDataContext(); return (from p in db.Products where p.ProductID == productId select p.ThumbNailPhoto).SingleOrDefault<Binary>().ToArray(); }
public int GetProductsCountByCategories(int[] categoryIds) { AdventureWorksDataContext db = new AdventureWorksDataContext(); return (from p in db.Products where categoryIds.Contains(p.ProductCategoryID.Value) select p).Count(); }
public ProductCategory[] GetCategories() { AdventureWorksDataContext db = new AdventureWorksDataContext(); return (from c in db.ProductCategories where c.ParentProductCategoryID == null select c).ToArray(); }
public ProductCategory[] GetSubcategories(string category) { AdventureWorksDataContext db = new AdventureWorksDataContext(); return (from c in db.ProductCategories where c.ParentProductCategoryID == GetCategoryId(category) select c).ToArray(); }
private int GetCategoryId(string category) { AdventureWorksDataContext db = new AdventureWorksDataContext(); var result = (from c in db.ProductCategories where c.Name == category select c.ProductCategoryID); return (result.Count<int>() > 0) ? result.First<int>() : -1; }
public Product[] GetProductsByCategories(int[] categoryIds, int page, int pageSize) { int startRowIndex = (page-1) * pageSize; int maximumRows = pageSize; AdventureWorksDataContext db = new AdventureWorksDataContext(); return (from p in db.Products where categoryIds.Contains(p.ProductCategoryID.Value) orderby p.Name ascending select p) .Skip(startRowIndex) .Take(maximumRows) .ToArray(); }
public Product GetProduct(int productId) { AdventureWorksDataContext db = new AdventureWorksDataContext(); return db.Products.Where(p => p.ProductID == productId).SingleOrDefault(); }
public int GetProductsCount() { AdventureWorksDataContext db = new AdventureWorksDataContext(); return db.Products.Count(); }