共用方式為


HOW TO:查詢資訊 (LINQ to SQL)

更新: November 2007

LINQ to SQL 中之查詢使用的語法與 LINQ 中的查詢相同。唯一的差別在於 LINQ to SQL 查詢中參考的物件會對應至資料庫中的項目。如需詳細資訊,請參閱 LINQ 查詢簡介

LINQ to SQL 會將您撰寫的查詢轉譯為對等 SQL 查詢,並將它們傳送給伺服器進行處理。

在 LINQ to SQL 應用程式中,可能需要特別注意 LINQ 查詢的部分功能。如需詳細資訊,請參閱 LINQ to SQL 的查詢概念

範例

下列查詢會要求來自倫敦 (London) 的客戶名單。在這個範例中,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;

請參閱

概念

下載範例資料庫 (LINQ to SQL)

其他資源

建立物件模型 (LINQ to SQL)

查詢資料庫 (LINQ to SQL)