Skip to content

Commit 377b6c4

Browse files
committed
Work in progress.
1 parent f9c63a9 commit 377b6c4

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

src/MongoDB.Driver/Linq/Linq3Implementation/KnownSerializerFinders/KnownSerializerFinderNewExpressionSerializerCreator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Reflection;
2121
using MongoDB.Bson.Serialization;
2222
using MongoDB.Driver.Linq.Linq3Implementation.Misc;
23+
using MongoDB.Driver.Linq.Linq3Implementation.Serializers;
2324
using MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators;
2425

2526
namespace MongoDB.Driver.Linq.Linq3Implementation.KnownSerializerFinders;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Linq.Expressions;
17+
18+
namespace MongoDB.Driver.Linq.Linq3Implementation.KnownSerializerFinders;
19+
20+
internal partial class KnownSerializerFinderVisitor
21+
{
22+
protected override Expression VisitListInit(ListInitExpression node)
23+
{
24+
var newExpression = node.NewExpression;
25+
var initializers = node.Initializers;
26+
27+
DeduceSerialiers();
28+
base.VisitListInit(node);
29+
DeduceSerialiers();
30+
31+
return node;
32+
33+
void DeduceSerialiers()
34+
{
35+
DeduceSerializers(node, newExpression);
36+
}
37+
}
38+
}

src/MongoDB.Driver/Linq/Linq3Implementation/KnownSerializerFinders/KnownSerializerFinderVisitMethodCall.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,10 @@ void DeduceAddMethodSerializers()
862862
{
863863
DeduceReturnsDateTimeSerializer();
864864
}
865+
else
866+
{
867+
DeduceUnknowableSerializer(node);
868+
}
865869
}
866870

867871
void DeduceAddDaysMethodSerializers()

tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationWithLinq2Tests/Translators/AggregateProjectTranslatorTests.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Linq.Expressions;
2020
using FluentAssertions;
2121
using MongoDB.Bson;
22+
using MongoDB.Bson.Serialization;
2223
using MongoDB.Driver;
2324
using MongoDB.Driver.Core.Misc;
2425
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
@@ -1756,9 +1757,16 @@ private ProjectedResult<TResult> Project<TResult>(Expression<Func<Root, TResult>
17561757
var query = __collection.AsQueryable().Select(projector);
17571758

17581759
var provider = (MongoQueryProvider<Root>)query.Provider;
1760+
var inputSerializer = (IBsonSerializer<Root>)provider.PipelineInputSerializer;
1761+
var serializerRegistry = provider.Collection.Settings.SerializerRegistry;
17591762
var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = false };
1760-
var executableQuery = ExpressionToExecutableQueryTranslator.Translate<Root, TResult>(provider, query.Expression, translationOptions);
1761-
var projection = executableQuery.Pipeline.Ast.Stages.First().Render()["$project"].AsBsonDocument;
1763+
var renderedProjection = LinqProviderAdapter.TranslateExpressionToProjection(
1764+
projector,
1765+
inputSerializer,
1766+
serializerRegistry,
1767+
translationOptions);
1768+
1769+
var projection = renderedProjection.Document;
17621770
var value = query.Take(1).FirstOrDefault();
17631771

17641772
return new ProjectedResult<TResult>

0 commit comments

Comments
 (0)