It retrieves just one record. Generated query will look like:
SELECT TOP(1) [t0].[TransactionKey]
FROM Receipt [t0]
ORDER BY [t0].[TransactionKey] DESC
Query is not executed until you call FirstOrDefault()
or other operator which forces execution (see Classification of Standard Query Operators by Manner of Execution).
You even can save query definition into variable (feel the difference - not result of query execution, but query itself)
var query = from r in GMSCore.db.Receipts
orderby r.TransactionKey descending
select r.TransactionKey;
// Nothing is executed yet
int tkey = query.FirstOrDefault(); // SQL query is generated and executed
You can execute original query later
foreach(var key in query) // another SQL is generated and executed
// ...
But in this case generated SQL query will look like
SELECT [t0].[TransactionKey]
FROM Receipt [t0]
ORDER BY [t0].[TransactionKey] DESC
So, you can modify query definition until it is executed. E.g. you can add filtering, or change ordering. In fact operator which executes query also usually affects query generation - e.g. selecting first, single or max item.