Your posts variable is of type IOrderedQueryable<Post> , but you assign it an IQueryable<Post> . I see two ways to solve this problem: either change the type of the variable, or IQueryable<Post> , or sort the query as follows:
posts = posts.Where(post => post.Body == searchString) .OrderBy(post => post.Date);
source share