1

我有一个像这样的 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

我究竟做错了什么?

4

2 回答 2

3

你知道你实际上是在做一个查询然后是一个内存过滤器,对吧?

像这样拆分它:

  var page = documentSession.Query<CMSPage>()
         .SingleOrDefault(p => p.Id == pageId);

和:

  var rows =             page.Rows
         .Any(x => x.Columns
           .Any(z => z.CMSModuleInstanceSettings
             .Where(m => m.IsActive == true)));

你现在在哪里得到错误?

于 2012-06-28T07:34:29.123 回答
1

我确信有更好的方法,但这就是我最终要做的......

var page = documentSession.Load<CMSPage>(pageId);

foreach (var row in page.Rows)
            {
                foreach (var column in row.Columns)
                {
                    var settings = column.CMSModuleInstanceSettings.ToList();
                    settings.ForEach(x => settings.Remove(x));
                    column.CMSModuleInstanceSettings = settings;
                }
            }
于 2012-06-28T21:30:58.217 回答