I want to reverse the output of a LINQ to SQL query. and .Reverse() does not work, just crashes the page.
protected void Page_Load(object sender, EventArgs e)
{
NewsDataContext db = new NewsDataContext();
var News = from news in db.News
select new
{
ID = news.NewsID,
kort = news.Short
};
foreach (var newa in News)
{
Panel1.
Controls.
Add(new LiteralControl(newa.kort +
"</br>" +
"<a href=Full.aspx?id=" +
newa.ID +
">Read The full Article</a>"));
}
}
Is there another way to reverse it?
If it's news you are trying to show, why not use an OrderBy (or OrderByDescending) to get the items in the order you want rather than the reverse order of the clustered index in the database.
I cannot think of any case where I would need to use Reverse in Linq to Sql.
Example (sorry if the Syntax if off, I prefer Lamda's):
var News =
(from news in db.News
orderby news.Date descending
select new
{
ID = news.NewsID,
kort = news.Short
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With