开发者

Retrieving top 50 rows from Table using LINQ

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 ?

Th开发者_运维百科anks !


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);


Like this:

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

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


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜