【问题标题】:RavenDb Hierarchial Data IndexRavenDb 分层数据索引
【发布时间】:2012-12-03 13:33:33
【问题描述】:

我的数据模型是:

public class Category
{
    public Guid Id { get; set; }
    public List<Category> children { get; set; }
}

我只想从任何级别的嵌套中获取数据。

我为此创建了一个索引:

public class CategoriesIndex : 
    AbstractIndexCreationTask<Category, CategoriesIndex.ReduceResult>
{
    public class ReduceResult
    {
        public Guid Id { get; set; }
        public Category Category { get; set; }
    }

    public CategoriesIndex()
    {
        Map = categories => 
            from category in categories
            from subcategory in category.Hierarchy(x=>x.children)
            select new {
                Id = subcategory.Id,
                Category = subcategory
            };

        Store(x => x.Id, FieldStorage.Yes);
        Store(x => x.Category, FieldStorage.Yes);
    }
}

运行该代码后出现异常

网址:“/indexes/CategoriesIndex”

System.InvalidOperationException:源代码。

怎么了?如果是,我如何索引分层数据?

附:由于某些限制,我无法更改数据模型

更新

我收到了异常消息:

public class Index_CategoriesIndex : AbstractViewGenerator
{
public Index_CategoriesIndex()
{
    this.ViewText = @"docs.Categories.SelectMany(category => category.Hierarchy(x => x.children), (category, subcategory) => new() {
Id = subcategory.Id,
Category = subcategory
})";

    this.ForEntityNames.Add("Categories");
    this.AddMapDefinition(docs => docs.Where(__document => __document["@metadata"]["Raven-Entity-Name"] == "Categories").SelectMany((Func<dynamic, IEnumerable<dynamic>>)(category => (IEnumerable<dynamic>)(category.Hierarchy(x => x.children))), (Func<dynamic, dynamic, dynamic>)((category, subcategory) => new { Id = subcategory.Id, Category = subcategory, __document_id = category.__document_id })));
    this.AddField("Id");
    this.AddField("Category");
    this.AddField("__document_id");
}
} e:\RavenDB\Web\Tenants\RavenPortalAuth\IndexDefinitions\TemporaryIndexDefinitionsAsSource\4jy1udpm.0.cs(21,223) :
error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

【问题讨论】:

    标签: c# .net indexing ravendb


    【解决方案1】:

    你应该使用 AbstractIndexCreationTask 的 Recurse 方法。

    http://ravendb.net/docs/2.0/client-api/querying/static-indexes/indexing-hierarchies

    【讨论】:

      猜你喜欢
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      相关资源
      最近更新 更多