此 Linq/Lambda 语句有问题:(
更新 - 我修复了下面的查询。我有错误的查询/错误语句:(
我有以下语句:
var posts = BlogPostRepository.Find()
.Where(x => x.Tags.Where(y => y.Name == tag))
.ToList();
它给我第二个(内部)Where 子句带来编译时错误,说:-
<块引用>错误 1 无法将 lambda 表达式转换为委托类型“System.Func”,因为块中的某些返回类型无法隐式转换为委托返回类型
我正在尝试按特定标记名称过滤所有 BlogPost。
Update - I fixed the query below. I had the wrong query/error statement :(
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这部分:
将返回
Tags
中具有Name == tag
的任何内容的 IEnumerable。然后你将其与“真实”进行比较,这没有多大意义。也许你想要这个?
或者代替“任何”、“全部”?
This part:
will return an IEnumerable of whatever is in
Tags
that haveName == tag
. You are then comparing that to "true" which doesn't make much sense.Perhaps you want this?
or instead of Any, All?