How to: Return the First Element in a Sequence (LINQ to SQL)
.NET Framework 4
Use the First operator to return the first element in a sequence. Queries that use First are executed immediately.
Note |
|---|
LINQ to SQL does not support the Last operator. |
The following code finds the first Shipper in a table:
If you run this query against the Northwind sample database, the results are
ID = 1, Company = Speedy Express.
The following code finds the single Customer that has the CustomerID BONAP.
If you run this query against the Northwind sample database, the results are ID = BONAP, Contact = Laurence Lebihan.
Note