0

私のデータモデルは次のとおりです。

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: "/indexes/CategoriesIndex"

System.InvalidOperationException: ソース コード。

どうしたの?また、階層データにインデックスを付けるにはどうすればよいですか?

PSいくつかの制限により、データモデルを変更できません

アップデート

例外のメッセージがあります:

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
4

1 に答える 1