我有一个RavenDb文件看起来像这样:“不能转换lambda表达式的委托类型”错误RavenDB查询
{
"ParentId": null,
"Order": 10,
"Url": "/sandbox",
"Rows":
[
{
"InstanceId": "2771a0d7-7f3f-4854-a3ba-27f25f88a45e",
"CSSClass": null,
"Columns":
[
{
"InstanceId": "b91495f5-b770-4da7-8073-ad3bd8221ca8",
"CSSClass": null,
"Span": 3,
"CMSModuleInstanceSettings":
[
{
"$type": "ModuleHTML.Models.ModuleHTMLInstanceSettings, ModuleHTML",
"IsActive": false,
"ShowAuthor": false,
"ShowDate": false,
"ShowCommentsCount": false,
"ShowLast2Comments": false,
"CMSModuleInstanceId": 417,
"ContainerClass": "default",
"ModuleType": "ModuleHTML",
"DisplayType": "Summary"
},
{
"$type": "ModuleHTML.Models.ModuleHTMLInstanceSettings, ModuleHTML",
"IsActive": false,
"ShowAuthor": false,
"ShowDate": false,
"ShowCommentsCount": false,
"ShowLast2Comments": false,
"CMSModuleInstanceId": 545,
"ContainerClass": "default",
"ModuleType": "ModuleHTML",
"DisplayType": "Summary"
}
],
"Id": 0,
"Name": null,
"CreatedOn": "0001-01-01T00:00:00.0000000",
"CreatedBy": 0,
"LastModifiedOn": "0001-01-01T00:00:00.0000000",
"LastModifiedBy": 0
},
...
],
...
},
...
],
...
}
,我想要检索的页面文件,包括行,列,然后只CMSModuleInstanceSettings是活动的。
我曾尝试:
var page = documentSession.Query<CMSPage>()
.SingleOrDefault(p => p.Id == pageId)
.Rows
.Any(x => x.Columns
.Any(z => z.CMSModuleInstanceSettings
.Where(m => m.IsActive == true)));
但它返回:
Error 1 Cannot convert lambda expression to delegate type
'System.Func<CMS.Models.CMSColumn,bool>' because some of
the return types in the block are not implicitly convertible
to the delegate return type
我在做什么错?
嗨Ayende,感谢您的答复。顺便说一句 - 乌鸦真棒! 错误\t \t 1无法转换lambda表达式委托类型“System.Func”,因为一些所述块中的返回类型的不隐式转换为委托返回类型 和第二误差: 错误不能隐式地将类型'System.Collections.Generic.IEnumerable '转换为'bool' –
最终我还是想返回一个页面对象,但是要过滤子对象。换句话说,我不想要一个Row集合。那可能吗? –
如果您确实需要子对象,则Any()不是您想要的。我猜你是LINQ的新手。你可能想要.Where()整个过程。我会将原始页面投影到具有过滤子集合的克隆中。 –