RavenDB升级:2.5到3.5-无法编译索引

RavenDB升级:2.5到3.5-无法编译索引,ravendb,ravendb-3.5,Ravendb,Ravendb 3.5,我目前正在将我们的解决方案从RavenDB 2.5升级到3.5,但在创建索引时出现以下异常:看起来它与分组方式有关 IndexCreation.CreateIndexes(typeof(RavenGuid).Assembly, store); 索引定义 public RecordingArtistTypeaheadIndex() { Map = docs => docs.Select(x => new Definition { Artist = x.ArtistDispla

我目前正在将我们的解决方案从RavenDB 2.5升级到3.5,但在创建索引时出现以下异常:看起来它与
分组方式有关

IndexCreation.CreateIndexes(typeof(RavenGuid).Assembly, store);
索引定义

public RecordingArtistTypeaheadIndex()
{
    Map = docs => docs.Select(x => new Definition { Artist = x.ArtistDisplayName });

    Reduce = results => results.SelectMany(r => r.Artist.Split('|')).GroupBy(x => x).Select(g => new Definition { Artist = g.Key });

    Store(x => x.Artist, FieldStorage.Yes);

    Index(x => x.Artist, FieldIndexing.Analyzed);
}
异常消息

Compilation Errors:

Line 40, Position 11: Error CS1525 - Invalid expression term 'by'
Line 40, Position 14: Error CS0745 - Expected contextual keyword 'by'
public class Index_RecordingArtistTypeaheadIndex : Raven.Database.Linq.AbstractViewGenerator
{
    public Index_RecordingArtistTypeaheadIndex()
    {
        this.ViewText = @"from x in docs.RepertoireResources
                          select new {
                              Artist = x.ArtistDisplayName
                          }
                          from x in results.SelectMany(r => r.Artist.Split(new char[] {'|'}))
                          group x by x into g
                          select new {
                              Artist = g.Key
                          }";

        this.ForEntityNames.Add("RepertoireResources");

        this.AddMapDefinition(docs => 
            from x in ((IEnumerable<dynamic>)docs)
            where string.Equals(x["@metadata"]["Raven-Entity-Name"], "RepertoireResources", System.StringComparison.InvariantCultureIgnoreCase)
            select new {
                Artist = x.ArtistDisplayName,
                __document_id = x.__document_id
            });

        this.ReduceDefinition = results => 
            from x in results.SelectMany((Func<dynamic, IEnumerable<dynamic>>)(r => (IEnumerable<dynamic>)(r.Artist.Split(new char[] {
                '|'
            }))))
            group  by x into g
            select new {
                Artist = g.Key
            };

        this.GroupByExtraction = x => x;
        this.AddField("Artist");
        this.AddQueryParameterForMap("ArtistDisplayName");
        this.AddQueryParameterForMap("__document_id");
        this.AddQueryParameterForReduce("ArtistDisplayName");
        this.AddQueryParameterForReduce("__document_id");
    }
}
源代码

Compilation Errors:

Line 40, Position 11: Error CS1525 - Invalid expression term 'by'
Line 40, Position 14: Error CS0745 - Expected contextual keyword 'by'
public class Index_RecordingArtistTypeaheadIndex : Raven.Database.Linq.AbstractViewGenerator
{
    public Index_RecordingArtistTypeaheadIndex()
    {
        this.ViewText = @"from x in docs.RepertoireResources
                          select new {
                              Artist = x.ArtistDisplayName
                          }
                          from x in results.SelectMany(r => r.Artist.Split(new char[] {'|'}))
                          group x by x into g
                          select new {
                              Artist = g.Key
                          }";

        this.ForEntityNames.Add("RepertoireResources");

        this.AddMapDefinition(docs => 
            from x in ((IEnumerable<dynamic>)docs)
            where string.Equals(x["@metadata"]["Raven-Entity-Name"], "RepertoireResources", System.StringComparison.InvariantCultureIgnoreCase)
            select new {
                Artist = x.ArtistDisplayName,
                __document_id = x.__document_id
            });

        this.ReduceDefinition = results => 
            from x in results.SelectMany((Func<dynamic, IEnumerable<dynamic>>)(r => (IEnumerable<dynamic>)(r.Artist.Split(new char[] {
                '|'
            }))))
            group  by x into g
            select new {
                Artist = g.Key
            };

        this.GroupByExtraction = x => x;
        this.AddField("Artist");
        this.AddQueryParameterForMap("ArtistDisplayName");
        this.AddQueryParameterForMap("__document_id");
        this.AddQueryParameterForReduce("ArtistDisplayName");
        this.AddQueryParameterForReduce("__document_id");
    }
}
公共类索引\u记录ArtistTypeaHeadIndex:Raven.Database.Linq.AbstractViewGenerator
{
公共索引\u记录ArtistTypeaHeadIndex()
{
docs.RepertoireResources中x的this.ViewText=@
选择新的{
艺术家=x.ArtistDisplayName
}
从results.SelectMany中的x(r=>r.Artist.Split(新字符[]{'|'}))
将x按x分组为g
选择新的{
艺术家=g.钥匙
}";
此.ForEntityNames.Add(“曲目资源”);
此.AddMapDefinition(文档=>
从((IEnumerable)文档中的x开始
其中string.Equals(x[“@metadata”][“Raven实体名称”],“RepertoireResources”,System.StringComparison.InvariantCultureIgnoreCase)
选择新的{
艺术家=x.ArtistDisplayName,
__文档id=x.\u文档id
});
this.ReduceDefinition=结果=>
从结果中的x选择many((Func)(r=>(IEnumerable)(r.Artist.Split)(新字符[]){
'|'
}))))
将x分组为g
选择新的{
艺术家=g.钥匙
};
this.GroupByExtraction=x=>x;
本文件为AddField(“艺术家”);
此.AddQueryParameterForMap(“ArtistDisplayName”);
此.AddQueryParameterForMap(“文档id”);
此.addQueryParametersForReduce(“ArtistDisplayName”);
此.AddQueryParameterForReduce(“\u\u文档\u id”);
}
}

以前有人遇到过这个问题吗?

解决方案:我更改了reduce,以便SelectMany返回匿名类型,然后我使用GroupBy中的.Artist属性

public RecordingArtistTypeaheadIndex()
{
    Map = docs => docs.Select(x => new Definition
    {
        Artist = x.ArtistDisplayName
    });

    Reduce = results => results
        .SelectMany(r => r.Artist.Split('|'), (x, y) => new Definition { Artist = y })
        .GroupBy(x => x.Artist)
        .Select(g => new Definition
        {
            Artist = g.Key
        });

    Store(x => x.Artist, FieldStorage.Yes);

    Index(x => x.Artist, FieldIndexing.Analyzed);
}

你没有分组。您使用Map/Reduce索引的目的是什么
GroupBy(x=>x)
我正在使用GroupBy删除重复项:)可能是个骗局。