Update - I fixed the query below. I had the wrong query/error stat开发者_Python百科ement :(
I have the following statement:
var posts = BlogPostRepository.Find()
.Where(x => x.Tags.Where(y => y.Name == tag))
.ToList();
It's giving me a compile time error with the 2nd (inner) Where clause, saying :-
Error 1 Cannot convert lambda expression to delegate type 'System.Func' because some of the return types in the block are not implicitly convertible to the delegate return type
I'm trying to filter all BlogPosts by a specific tag name.
This part:
x.Tags.Where(y => y.Name == tag)
will return an IEnumerable of whatever is in Tags
that have Name == tag
. You are then comparing that to "true" which doesn't make much sense.
Perhaps you want this?
var posts = BlogPostRepository.Find()
.Where(x => x.Tags.Any(y => y.Name == tag))
.ToList()
or instead of Any, All?
精彩评论