Aracılığıyla paylaş


How to: Query for Information (LINQ to SQL)

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.

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 in LINQ to SQL.

Example

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

Dim db As New Northwnd("c:\northwnd.mdf")

' Query for customers in London. 
Dim custQuery = _
    From cust In db.Customers _
    Where cust.City = "London" _
    Select cust
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;

See Also

Concepts

Downloading Sample Databases (LINQ to SQL)

Other Resources

Creating the Object Model (LINQ to SQL)

Querying the Database (LINQ to SQL)