如何:查询信息 (LINQ to SQL)
更新:November 2007
LINQ to SQL 中的查询与 LINQ 中的查询使用相同的语法。唯一的差异是 LINQ to SQL 查询中引用的对象映射到数据库中的元素。有关更多信息,请参见 LINQ 查询介绍。
LINQ to SQL 将您编写的查询转换成等效的 SQL 查询,然后将它们发送至服务器进行处理。
在 LINQ to SQL 应用程序中,可能需要特别注意 LINQ 查询的某些功能。有关更多信息,请参见 LINQ to SQL 中的查询概念。
示例
下面的查询请求来自伦敦的客户的列表。在此示例中,Customers 是 Northwind 示例数据库中的表。
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;