Solved

IQueryable

Posted on 2014-09-11
1
147 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 75

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

828 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