O'Reilly logo

Entity Framework Tutorial - Second Edition by Joydip Kanjilal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Querying data using LINQ

Let's take a look at how we can use LINQ to query data in our applications. The following code snippet illustrates how you can use LINQ to display the contents of an array:

String[] employees = {"Joydip", "Douglas", "Jini", "Piku", "Amal",
                      "Rama", "Indronil"};
var employeeNames = from employee in employees select employee;
foreach (var empName in employeeNames)
    Response.Write(empName);

Now, let's discuss how to use LINQ to query a generic list. Consider the following GenericEmployeeList list:

public List<String> GenericEmployeeList = new List<String>()
{
  "Joydip", "Douglas", "Jini", "Piku",
  "Rama", "Amal", "Indronil"
};

You can use LINQ to query this list as shown in the following code snippet:

IEnumerable<String> employees ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required