tags:

views:

82

answers:

3

Hey,

Am new to LINQ, and am trying to retrieve the top 50 rows of a particular table.

In SQL Server using an actual query i coudl say "Select TOP 50 from Transactions" , but not sure how i need to do that with LinQ

Any pointers that could help ?

Thanks !

A: 

Something like this would do it.

collection = (from e in table select e).Top(50)

EDIT: Oops, I knew it didn't look right.

collection = (from e in table select e).Take(50)
helios456
Top isn't a Linq keyword.
Keltex
A: 

Like this:

var list = db.Transactions.Take(50);

Of course this doesn't include any ordering or sorting which your query will probably need.

Keltex
+2  A: 

Here is a basic example doing a select with a where and getting 50 records:

var transactions = (from t in db.Transactions
    where t.Name.StartsWith("A")
    select t).Take(50);

Using other syntax:

var transactions = db.Transactions.Where(t => t.Name.StartsWith("A")).Take(50);
Kelsey
Ah Thanks ! i was using the Take incorrectly
James
@James if my answer helped you please mark it as the accepted answer :)
Kelsey