// The return type can be changed to IEnumerable, however to support
        // paging and sorting, the following parameters must be added:
        //     int maximumRows
        //     int startRowIndex
        //     out int totalRowCount
        //     string sortByExpression
        public IQueryable <WebApplication2.Model.Product> GetProducts([QueryString("id")] int?categoryId)
        {
            var _db = new WebApplication2.Model.ProductContext();
            IQueryable <WebApplication2.Model.Product> query = _db.Products;

            if (categoryId.HasValue && categoryId > 0)
            {
                query = query.Where(p => p.CategoryID == categoryId);
            }
            return(query);
        }
Пример #2
0
        // The id parameter should match the DataKeyNames value set on the control
        // or be decorated with a value provider attribute, e.g. [QueryString]int id
        public IQueryable <Product> GetProduct([QueryString("productID")] int?productId)
        {
            var _db = new WebApplication2.Model.ProductContext();
            IQueryable <WebApplication2.Model.Product> query = _db.Products;

            if (productId.HasValue && productId > 0)
            {
                query = query.Where(p => p.ProductID == productId);
            }
            else
            {
                query = null;
            }
            return(query);
        }