Skip to content

Commit 0b92d63

Browse files
committed
Added domain to MongoQueryProvider
1 parent 962861f commit 0b92d63

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

src/MongoDB.Driver/Linq/Linq3Implementation/MongoQueryProvider.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ internal sealed class MongoQueryProvider<TDocument> : MongoQueryProvider
6464
private readonly IMongoDatabase _database;
6565
private ExecutableQuery<TDocument> _executedQuery;
6666
private readonly IBsonSerializer _pipelineInputSerializer;
67+
private readonly IBsonSerializationDomain _serializationDomain;
6768

6869
// constructors
6970
public MongoQueryProvider(
@@ -74,6 +75,7 @@ public MongoQueryProvider(
7475
{
7576
_collection = Ensure.IsNotNull(collection, nameof(collection));
7677
_pipelineInputSerializer = collection.DocumentSerializer;
78+
_serializationDomain = collection.Settings.SerializationDomain;
7779
}
7880

7981
public MongoQueryProvider(
@@ -84,15 +86,18 @@ public MongoQueryProvider(
8486
{
8587
_database = Ensure.IsNotNull(database, nameof(database));
8688
_pipelineInputSerializer = NoPipelineInputSerializer.Instance;
89+
_serializationDomain = _database.Settings.SerializationDomain;
8790
}
8891

8992
internal MongoQueryProvider(
9093
IBsonSerializer pipelineInputSerializer,
9194
IClientSessionHandle session,
92-
AggregateOptions options)
95+
AggregateOptions options,
96+
IBsonSerializationDomain serializationDomain)
9397
: base(session, options)
9498
{
9599
_pipelineInputSerializer = Ensure.IsNotNull(pipelineInputSerializer, nameof(pipelineInputSerializer));
100+
_serializationDomain = Ensure.IsNotNull(serializationDomain, nameof(serializationDomain));
96101
}
97102

98103
// public properties
@@ -101,6 +106,7 @@ internal MongoQueryProvider(
101106
public IMongoDatabase Database => _database;
102107
public override BsonDocument[] LoggedStages => _executedQuery?.LoggedStages;
103108
public override IBsonSerializer PipelineInputSerializer => _pipelineInputSerializer;
109+
public IBsonSerializationDomain SerializationDomain => _serializationDomain;
104110

105111
// public methods
106112
public override IQueryable CreateQuery(Expression expression)

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExpressionToExecutableQueryTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static ExecutableQuery<TDocument, IAsyncCursor<TOutput>> Translate<TDocum
3131
{
3232
expression = PartialEvaluator.EvaluatePartially(expression);
3333

34-
var context = TranslationContext.Create(translationOptions, provider.Collection.Settings.SerializationDomain);
34+
var context = TranslationContext.Create(translationOptions, provider.SerializationDomain);
3535
var pipeline = ExpressionToPipelineTranslator.Translate(context, expression);
3636

3737
return ExecutableQuery.Create(

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/LookupMethodToPipelineTranslator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private static TranslatedPipeline TranslateDocumentsPipelineGeneric<TLocal, TDoc
286286
var localSymbol = context.CreateSymbol(localParameter, localAst, localSerializer);
287287
context = context.WithSymbol(localSymbol);
288288

289-
var provider = new MongoQueryProvider<TDocument>(documentSerializer, session: null, options: null);
289+
var provider = new MongoQueryProvider<TDocument>(documentSerializer, session: null, options: null, serializationDomain: context.SerializationDomain);
290290
var queryable = new MongoQuery<TDocument, TDocument>(provider);
291291

292292
body = ExpressionReplacer.Replace(body, queryableParameter, Expression.Constant(queryable));

tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp5286Tests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ public Type GetActualType(IBsonReader bsonReader, Type nominalType, IBsonSeriali
161161
}
162162

163163
public BsonValue GetDiscriminator(Type nominalType, Type actualType) => actualType.Name;
164-
public BsonValue GetDiscriminator(Type nominalType, Type actualType, IBsonSerializationDomain domain)
165-
{
166-
throw new NotImplementedException();
167-
}
164+
165+
public BsonValue GetDiscriminator(Type nominalType, Type actualType, IBsonSerializationDomain domain) =>
166+
actualType.Name;
168167

169168
public BsonValue[] GetDiscriminatorsForTypeAndSubTypes(Type type)
170169
{

0 commit comments

Comments
 (0)