It should be OrderByDescending
instead of OrderBy
if you want to replicate the results for the SQL Query.
Additionally, if you look at your query:
NewsletterGetAll()
.FirstOrDefault(c => c.NEWSLETTER_CATEGORY_ID == 1)
.OrderBy(a => a.Creation_Date)
In SQL this would be ok, since it evaluates the ORDER BY
before the TOP
expression. However, in Linq it will take the first record that matches the category, and then order that single record. So this won't even build, you cannot sort a single item.
Therefore it should be
NewsletterGetAll()
.Where(c => c.NEWSLETTER_CATEGORY_ID == 1)
.OrderByDescending(c => c.Creation_Date)
.FirstOrDefault();