-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSHARP-5356: Support OfType
and is
with scalar discriminators when using class mapped serializers.
#1559
base: main
Are you sure you want to change the base?
CSHARP-5356: Support OfType
and is
with scalar discriminators when using class mapped serializers.
#1559
Changes from 1 commit
31273b8
1128d64
c048bb4
0346c91
0488d2f
fd329f2
00c3a11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…pe and Where.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,17 @@ public static AggregationExpression Translate(TranslationContext context, Method | |
{ | ||
var sourceExpression = arguments[0]; | ||
var sourceTranslation = ExpressionToAggregationExpressionTranslator.TranslateEnumerable(context, sourceExpression); | ||
var itemSerializer = ArraySerializerHelper.GetItemSerializer(sourceTranslation.Serializer); | ||
NestedAsQueryableHelper.EnsureQueryableMethodHasNestedAsQueryableSource(expression, sourceTranslation); | ||
|
||
var sourceAst = sourceTranslation.Ast; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block of code is to support wrapped arrays as input to the stage. |
||
var sourceSerializer = sourceTranslation.Serializer; | ||
if (sourceSerializer is IWrappedValueSerializer wrappedValueSerializer) | ||
{ | ||
sourceAst = AstExpression.GetField(sourceAst, wrappedValueSerializer.FieldName); | ||
sourceSerializer = wrappedValueSerializer.ValueSerializer; | ||
} | ||
var itemSerializer = ArraySerializerHelper.GetItemSerializer(sourceSerializer); | ||
|
||
var predicateLambda = ExpressionHelper.UnquoteLambdaIfQueryableMethod(method, arguments[1]); | ||
var predicateParameter = predicateLambda.Parameters[0]; | ||
var predicateSymbol = context.CreateSymbol(predicateParameter, itemSerializer); | ||
|
@@ -57,7 +65,7 @@ public static AggregationExpression Translate(TranslationContext context, Method | |
} | ||
|
||
var ast = AstExpression.Filter( | ||
sourceTranslation.Ast, | ||
sourceAst, | ||
predicateTranslation.Ast, | ||
@as: predicateSymbol.Var.Name, | ||
limitTranslation?.Ast); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ private class B : A | |
{ | ||
} | ||
|
||
[BsonDiscriminator(RootClass = true)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This must have been an oversight. |
||
[BsonKnownTypes(typeof(E))] | ||
private class C : A | ||
{ | ||
|
@@ -77,7 +76,7 @@ public void TestDeserializeEAsA() | |
{ | ||
var document = new BsonDocument | ||
{ | ||
{ "_t", new BsonArray { "C", "E" } }, | ||
{ "_t", "E" }, | ||
{ "P", "x" } | ||
}; | ||
|
||
|
@@ -86,7 +85,7 @@ public void TestDeserializeEAsA() | |
Assert.IsType<E>(rehydrated); | ||
|
||
var json = rehydrated.ToJson<A>(); | ||
var expected = "{ '_t' : ['C', 'E'], 'P' : 'x' }".Replace("'", "\""); | ||
var expected = "{ '_t' : 'E', 'P' : 'x' }".Replace("'", "\""); | ||
Assert.Equal(expected, json); | ||
Assert.True(bson.SequenceEqual(rehydrated.ToBson<A>())); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block of code is to support wrapped arrays as input to the stage.