2012-12-03 46 views
0

我的数据模型是:RavenDb Hierarchial数据索引

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); 
    } 
} 

运行的代码后我有一个例外

URL: “/索引/ CategoriesIndex”

系统。 InvalidOperationException:源代码。

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

P.S.我不能将数据模型,由于一些限制

更新改变

我已经得到了异常的消息:

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 

回答