Select Top(8) * from products order by CreatedOn desc can u convert this query to Linq List where product is a table in sql Created on is a dateTime comumn..
Asked
Active
Viewed 364 times
3 Answers
4
var result = (from p in products
orderby p.CreatedOn descending
select p).Take(8);
OR
var result = products.OrderByDescending(p=>p.CreatedOn).Take(8);

Timwi
- 65,159
- 33
- 165
- 230

Cheng Chen
- 42,509
- 16
- 113
- 174
-
@Marko Ivanovski @Timwi - sorry a typo, thanks for your help. – Cheng Chen Sep 15 '10 at 06:12
1
Have a look at the Linq to Sql Cheat Sheet. It contains a lot of useful, easy to follow LinqToSql information and is available for C# and VB.NET.
Relating to your query, look at the Paging and Order section, taking out the Skip(x) part of the query, and and replace the .Take(5) with your .Take(8) for your Top(8) value.

Riaan
- 1,541
- 2
- 20
- 31
-1
Check this StackOverflow question which talks about converting similar kind of query:
Converting SQL containing top, count, group and order to LINQ (2 Entities)

Community
- 1
- 1

Sachin Shanbhag
- 54,530
- 11
- 89
- 103
-
@Timwi - Thanks. Did not realize it was a duplicate from stack overflow itself. – Sachin Shanbhag Sep 15 '10 at 05:58