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..
A:
Check this StackOverflow question which talks about converting similar kind of query:
Also better work out on your accept rate too.
Sachin Shanbhag
2010-09-15 05:41:21
@Timwi - Thanks. Did not realize it was a duplicate from stack overflow itself.
Sachin Shanbhag
2010-09-15 05:58:00
+3
A:
var result = (from p in products
orderby p.CreatedOn descending
select p).Take(8);
OR
var result = products.OrderByDescending(p=>p.CreatedOn).Take(8);
Danny Chen
2010-09-15 05:43:29
+1
A:
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
2010-09-15 05:53:01