Possible Duplicate:
LINQ2SQL: Cannot convert IQueryable<> to IOrderedQueryable error
I having this error in the searchString of my controller..
here is my codes:
if (!String.IsNullOrEmpty(searchString))
{
posts = posts.Where(post => post.Body == searchString);
}
I'm using this codes for my search in my Index. Did I declare something wrong here or something? I already tried googling but didn't find a clear answer. Thanks in advance for anyone who could help me..
The most likely cause is that you used an implicit var
declaration for posts
in a query that has an OrderBy
. If you replace it with
IQueryable<Post> posts = someSource.Where(cond).OrderBy(/*the culprit*/);
the error should go away.
Your posts
variable seems to be of type IOrderedQueryable<Post>
but you are assigning it a IQueryable<Post>
. I see 2 ways to resolve this, either modify your variable type to be IQueryable<Post>
or sort your query like this:
posts = posts.Where(post => post.Body == searchString)
.OrderBy(post => post.Date);
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