Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Guys!
I am in developing a new articles website for someone in ASP using C# but there is a problem, that i want to implement the (Five most Viewed Articles) sometimes called (Five Most Popular Articles) How i can???
the code may in LINQ if not then in Straight forward Querying with SQL Server 2008 R2
pleaaaaaaaaaaaaaaaaase help me
Posted
Updated 5-Sep-12 17:45pm
v2

Try the following in LINQ:
C#
var list = (from article in ArticleTable
           where <apply your condition>
           orderby article.LastViewedTime
           select article ).Take(5);

Navigate the following links for further details on LINQ:
101 LINQ Samples
LINQ to SQL - Select Top N Rows
TOP/LIMIT Support for LINQ
 
Share this answer
 
v2
SQL
SELECT TOP 5 ArticleTitle, ArticleInfo
FROM ArticleTable
ORDER BY TimesViewed DESC



Lets say you have ArticleTable and TimesViewed Column keeps track of how many times article has been viewed.The TOP Keyword in SQL will be able to fetch the record based on the count you supply,in your case it is 5.
 
Share this answer
 
Comments
khaksar weqar 6-Sep-12 8:05am    
But i havnt TimesViewed Column, if i create then how i can keep the track of times viewed of article, can u tell me the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900