RavenDB 升级:2.5 到 3.5 - 无法编译索引
RavenDB Upgrade: 2.5 to 3.5 - Cannot compile index
我目前正在将我们的解决方案从 RavenDB 2.5 升级到 3.5,但在创建索引时出现以下异常:看起来它与 group by
有关
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");
}
}
有人遇到过这个吗?
解决方案: 我更改了 reduce 以便 SelectMany returns 成为匿名类型,然后我在 GroupBy[=] 中使用 .Artist 属性 11=]
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);
}
我目前正在将我们的解决方案从 RavenDB 2.5 升级到 3.5,但在创建索引时出现以下异常:看起来它与 group by
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");
}
}
有人遇到过这个吗?
解决方案: 我更改了 reduce 以便 SelectMany returns 成为匿名类型,然后我在 GroupBy[=] 中使用 .Artist 属性 11=]
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);
}