I am Printing all latest records depending on when a book was published.(PubEnd). Now I am able to print all the books that are published in descending order.
I need to print the 20 Latest published titles. How can I do that??
Right now the code below is printing all books published in descending order.
var query = docs.Descendants(name)
.Select(x => new
{
Title = (string)x.Element(ns + "TITLE"),
Status = (string)x.Element(ns + "STATUS"),
PubEnd = (string)x.Element(ns + "PUB_END")
})
.Select(x => new
{
Title = x.Title,
Status = x.Status,
PubEnd = x.PubEnd,
}).OrderByDescending(x => x.PubEnd).ToList();
foreach (var book in query)
{
if (book.Status == "Published")
{
Response.Write(book.Title);
Response.Write(book.Status);
Response.Write(book.PubEnd);
}
}
Take(20)This should be what you need:
If you want to get distinct result: