# How could I remove repetition from this linq-to-entities query?

This linq query works, and it does what I want it to do, but is there any other way I could improve the query so I'm not repeating a.AnswerRevisions.OrderByDescending(r => r.DateCreated).FirstOrDefault()?

IQueryable<Article> query = from a in _db.Articles
orderby a.DateCreated descending
select a;

• I'd rather do .UpVotes < .Downvotes. May 8 '12 at 13:14

Use the let statement and also do the final orderby after the where clause, this will increase efficiency, as less entries will have to be sorted

IQueryable<Article> query = from a in _db.Articles
let  rev = a.AnswerRevisions.OrderByDescending(r => r.DateCreated).FirstOrDefault()

• It might make no difference with EF, but if you have linq-to-objects it will. In SQL the order by comes always after where. It feels better to have order by at the end. Jul 13 '16 at 18:54