Solved

IQueryable

Posted on 2014-09-11
1
144 Views
Last Modified: 2016-02-18
If Someone could help me understand this piece of code bellow

public<Product> GetProducts([QueryString("id")] int? categoryId)
        {
            var _db = new WingtipToys.Models.ProductContext();
                IQueryable<Product> query = _db.Products;
                if (categoryId.HasValue && categoryId > 0)
                {
                    query = query.Where(p => p.CategoryID == categoryId);
                }
                return query;
        }

Open in new window

0
Comment
Question by:yguyon28
1 Comment
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40318481
You have a method named GetProducts, which takes in a (nullable) integer. This value comes from the querystring parameter named "id", which would be passed in a web request to your service/web page. Inside the method, you create a new database context which you will use to interact with your database. From the database, you will be retrieving information from the Products table. In your code, the Products table is represented as  an IQueryable of Product--vaguely like a list of products. An IQueryable just means that this is something that you can query with LINQ, and typically the data originates from a database. So you search through this list of products using the categoryId value that came in as a parameter. Wherever the category ID matches in a database record (from the IQueryable), you will return it from the method.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now