How to: Query for Information

How to: Query for Information


Queries in LINQ to SQL use the same syntax as queries in LINQ. The only difference is that the objects referenced in LINQ to SQL queries are mapped to elements in a database. For more information, see Introduction to LINQ Queries (C#).

LINQ to SQL translates the queries you write into equivalent SQL queries and sends them to the server for processing.

Some features of LINQ queries might need special attention in LINQ to SQL applications. For more information, see Query Concepts.

The following query asks for a list of customers from London. In this example, Customers is a table in the Northwind sample database.

Northwnd db = new Northwnd(@"c:\northwnd.mdf");

// Query for customers in London.
IQueryable<Customer> custQuery =
    from cust in db.Customers
    where cust.City == "London"
    select cust;
© 2015 Microsoft