その長所と短所は、このビットをRavenマルチマップクエリに追加しようとしていることです。
this.AddMap<Ownership>(ownerships => from o in ownerships
select new
{
CardId = o.CardId,
Expansion = (string)null,
Owned = 1,
Rarity = (string)null,
Artist = Enumerable.Empty<string>(),
Colors = Enumerable.Empty<string>(),
ConvertedManaCost = Enumerable.Empty<decimal?>(),
Name = Enumerable.Empty<string>(),
Power = Enumerable.Empty<string>(),
Text = Enumerable.Empty<string>(),
Toughness = Enumerable.Empty<string>(),
Types = Enumerable.Empty<string>(),
});
そして、レイヴンはその式をこれに変換します(読みやすさのためにフォーマットされています):
this.ForEntityNames.Add("Ownerships");
this.AddMapDefinition(docs => docs
.Where(__document => __document["@metadata"]["Raven-Entity-Name"] == "Ownerships")
.Select((Func<dynamic, dynamic>)(o => new
{
CardId = o.CardId,
Expansion = (System.String)null,
Owned = 1,
Rarity = (System.String)null,
Artist = Enumerable.Empty(),
Colors = Enumerable.Empty(),
ConvertedManaCost = Enumerable.Empty(),
Name = Enumerable.Empty(),
Power = Enumerable.Empty(),
Text = Enumerable.Empty(),
Toughness = Enumerable.Empty(),
Types = Enumerable.Empty(),
__document_id = o.__document_id
})));
'System.Linq.Enumerable.Empty<TResult>()' cannot be inferred from the usage. Try specifying the type arguments explicitly.
これは明らかな理由で爆発します。
このいまいましいことを機能させる方法はありますか?
Enumerable.Empty()の代わりに試してみましたがnew string[0]
、どちらも次のように失敗します。new string[] { }
System.InvalidOperationException: Could not understand query:
-- line 2 col 219: invalid NewExpression
-- line 2 col 259: Can't parse double .0.0
at Raven.Database.Linq.QueryParsingUtils.GetVariableDeclarationForLinqMethods(String query, Boolean requiresSelectNewAnonymousType) in c:\Builds\RavenDB-Stable\Raven.Database\Linq\QueryParsingUtils.cs:line 124
at Raven.Database.Linq.DynamicViewCompiler.TransformMapDefinitionFromLinqMethodSyntax(String query, String& entityName) in c:\Builds\RavenDB-Stable\Raven.Database\Linq\DynamicViewCompiler.cs:line 355
at Raven.Database.Linq.DynamicViewCompiler.HandleMapFunction(ConstructorDeclaration ctor, String map) in c:\Builds\RavenDB-Stable\Raven.Database\Linq\DynamicViewCompiler.cs:line 132
at Raven.Database.Linq.DynamicViewCompiler.TransformQueryToClass() in c:\Builds\RavenDB-Stable\Raven.Database\Linq\DynamicViewCompiler.cs:line 97
at Raven.Database.Linq.DynamicViewCompiler.GenerateInstance() in c:\Builds\RavenDB-Stable\Raven.Database\Linq\DynamicViewCompiler.cs:line 489
at Raven.Database.DocumentDatabase.PutIndex(String name, IndexDefinition definition) in c:\Builds\RavenDB-Stable\Raven.Database\DocumentDatabase.cs:line 724
at Raven.Database.Server.Responders.Index.Put(IHttpContext context, String index) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\Index.cs:line 71
at Raven.Database.Server.Responders.Index.Respond(IHttpContext context) in c:\Builds\RavenDB-Stable\Raven.Database\Server\Responders\Index.cs:line 48
at Raven.Database.Server.HttpServer.DispatchRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 548
at Raven.Database.Server.HttpServer.HandleActualRequest(IHttpContext ctx) in c:\Builds\RavenDB-Stable\Raven.Database\Server\HttpServer.cs:line 315
私のReduceは次のようになります。
this.Reduce = results => from r in results
group r by r.CardId into g
select new
{
CardId = g.Key,
Expansion = g.Select(r => r.Expansion).Where(v => v != null).FirstOrDefault(),
Owned = g.Sum(r => r.Owned),
Rarity = g.Select(r => r.Rarity).Where(v => v != null).FirstOrDefault(),
Artist = g.SelectMany(r => r.Artist),
Colors = g.SelectMany(r => r.Colors),
ConvertedManaCost = g.SelectMany(r => r.ConvertedManaCost),
Name = g.SelectMany(r => r.Name),
Power = g.SelectMany(r => r.Power),
Text = g.SelectMany(r => r.Text),
Toughness = g.SelectMany(r => r.Toughness),
Types = g.SelectMany(r => r.Types),
};
そして私の他の地図はこのように見えます:
this.AddMap<Card>(cards => from c in cards
select new
{
CardId = c.Id.ToString(),
Expansion = c.Expansion,
Owned = 0,
Rarity = c.Rarity,
Artist = c.NormalizedFaces.Select(f => f.Artist),
Colors = c.Colors,
ConvertedManaCost = c.NormalizedFaces.Select(f => f.ConvertedManaCost),
Name = c.NormalizedFaces.Select(f => f.Name),
Power = c.NormalizedFaces.Select(f => f.Power),
Text =
c.NormalizedFaces.Select(f => f.Name)
.Concat(c.NormalizedFaces.SelectMany(f => f.CardText))
.Concat(c.NormalizedFaces.Select(f => f.Types))
.Concat(c.NormalizedFaces.SelectMany(f => f.FlavorText)),
Toughness = c.NormalizedFaces.Select(f => f.Toughness),
Types = c.NormalizedFaces.Select(f => f.Types),
});
ただし、インデックスは1つのマップで機能し、reduceであるため、これらが原因ではないと確信しています。