Skip to content

Commit 0e56324

Browse files
committed
CSHARP-5233: Remove IMongoQueryable interface.
1 parent 2a0fd60 commit 0e56324

File tree

42 files changed

+761
-1069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+761
-1069
lines changed

src/MongoDB.Driver/IMongoCollectionExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
using System;
1717
using System.Collections.Generic;
18+
using System.Linq;
1819
using System.Linq.Expressions;
1920
using System.Threading;
2021
using System.Threading.Tasks;
@@ -67,7 +68,7 @@ public static IAggregateFluent<TDocument> Aggregate<TDocument>(this IMongoCollec
6768
/// <param name="collection">The collection.</param>
6869
/// <param name="aggregateOptions">The aggregate options</param>
6970
/// <returns>A queryable source of documents.</returns>
70-
public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions aggregateOptions = null)
71+
public static IQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, AggregateOptions aggregateOptions = null)
7172
{
7273
Ensure.IsNotNull(collection, nameof(collection));
7374

@@ -82,7 +83,7 @@ public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoColle
8283
/// <param name="session">The session.</param>
8384
/// <param name="aggregateOptions">The aggregate options</param>
8485
/// <returns>A queryable source of documents.</returns>
85-
public static IMongoQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions aggregateOptions = null)
86+
public static IQueryable<TDocument> AsQueryable<TDocument>(this IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions aggregateOptions = null)
8687
{
8788
Ensure.IsNotNull(collection, nameof(collection));
8889
Ensure.IsNotNull(session, nameof(session));
@@ -2652,7 +2653,7 @@ public static Task<IChangeStreamCursor<ChangeStreamDocument<TDocument>>> WatchAs
26522653
}
26532654

26542655
// private static methods
2655-
private static IMongoQueryable<TDocument> AsQueryableHelper<TDocument>(IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions aggregateOptions)
2656+
private static IQueryable<TDocument> AsQueryableHelper<TDocument>(IMongoCollection<TDocument> collection, IClientSessionHandle session, AggregateOptions aggregateOptions)
26562657
{
26572658
aggregateOptions = aggregateOptions ?? new AggregateOptions();
26582659
return LinqProviderAdapter.AsQueryable(collection, session, aggregateOptions);

src/MongoDB.Driver/IMongoDatabaseExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System.Linq;
1617
using System.Threading;
1718
using System.Threading.Tasks;
1819
using MongoDB.Bson;
@@ -62,7 +63,7 @@ public static IAggregateFluent<NoPipelineInput> Aggregate(this IMongoDatabase da
6263
/// <param name="database">The database.</param>
6364
/// <param name="aggregateOptions">The aggregate options</param>
6465
/// <returns>A queryable source of documents.</returns>
65-
public static IMongoQueryable<NoPipelineInput> AsQueryable(this IMongoDatabase database, AggregateOptions aggregateOptions = null)
66+
public static IQueryable<NoPipelineInput> AsQueryable(this IMongoDatabase database, AggregateOptions aggregateOptions = null)
6667
{
6768
Ensure.IsNotNull(database, nameof(database));
6869

@@ -76,7 +77,7 @@ public static IMongoQueryable<NoPipelineInput> AsQueryable(this IMongoDatabase d
7677
/// <param name="session">The session.</param>
7778
/// <param name="aggregateOptions">The aggregate options</param>
7879
/// <returns>A queryable source of documents.</returns>
79-
public static IMongoQueryable<NoPipelineInput> AsQueryable(this IMongoDatabase database, IClientSessionHandle session, AggregateOptions aggregateOptions = null)
80+
public static IQueryable<NoPipelineInput> AsQueryable(this IMongoDatabase database, IClientSessionHandle session, AggregateOptions aggregateOptions = null)
8081
{
8182
Ensure.IsNotNull(database, nameof(database));
8283
Ensure.IsNotNull(session, nameof(session));
@@ -167,7 +168,7 @@ public static Task<IChangeStreamCursor<ChangeStreamDocument<BsonDocument>>> Watc
167168
}
168169

169170
// private static methods
170-
private static IMongoQueryable<NoPipelineInput> AsQueryableHelper(IMongoDatabase database, IClientSessionHandle session, AggregateOptions aggregateOptions)
171+
private static IQueryable<NoPipelineInput> AsQueryableHelper(IMongoDatabase database, IClientSessionHandle session, AggregateOptions aggregateOptions)
171172
{
172173
aggregateOptions = aggregateOptions ?? new AggregateOptions();
173174
return LinqProviderAdapter.AsQueryable(database, session, aggregateOptions);

src/MongoDB.Driver/Linq/IMongoQueryable.cs

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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;
17+
using System.Linq;
18+
using MongoDB.Bson;
19+
using MongoDB.Driver.Core.Misc;
20+
21+
namespace MongoDB.Driver.Linq
22+
{
23+
/// <summary>
24+
/// Extension methods for IQueryble.
25+
/// </summary>
26+
public static class IQueryableExtensions
27+
{
28+
29+
/// <summary>
30+
/// Gets the most recently logged stages.
31+
/// </summary>
32+
/// <typeparam name="TSource">The type of the source documents.</typeparam>
33+
/// <param name="source">The source.</param>
34+
/// <returns>The logged stages.</returns>
35+
public static BsonDocument[] GetLoggedStages<TSource>(this IQueryable<TSource> source)
36+
{
37+
Ensure.IsNotNull(source, nameof(source));
38+
return source.GetMongoQueryProvider().LoggedStages;
39+
}
40+
41+
/// <summary>
42+
/// Gets the source's provider cast to an IMongoQueryProvider.
43+
/// </summary>
44+
/// <param name="source">The source.</param>
45+
/// <returns>The MongoDB query provider.</returns>
46+
public static IMongoQueryProvider GetMongoQueryProvider(this IQueryable source)
47+
{
48+
Ensure.IsNotNull(source, nameof(source));
49+
var provider = source.Provider as IMongoQueryProvider;
50+
if (provider == null)
51+
{
52+
throw new ArgumentException($"The source argument must be a MongoDB IQueryable.", nameof(source));
53+
}
54+
55+
return provider;
56+
}
57+
}
58+
}

src/MongoDB.Driver/Linq/Linq3Implementation/ExtensionMethods/ExpressionExtensions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System;
17+
using System.Linq;
1718
using System.Linq.Expressions;
1819
using MongoDB.Bson.Serialization;
1920

@@ -38,14 +39,14 @@ public static object Evaluate(this Expression expression)
3839
public static (string CollectionName, IBsonSerializer DocumentSerializer) GetCollectionInfo(this Expression innerExpression, Expression containerExpression)
3940
{
4041
if (innerExpression is ConstantExpression constantExpression &&
41-
constantExpression.Value is IMongoQueryable mongoQueryable &&
42-
mongoQueryable.Provider is IMongoQueryProviderInternal mongoQueryProvider &&
42+
constantExpression.Value is IQueryable queryable &&
43+
queryable.Provider is IMongoQueryProviderInternal mongoQueryProvider &&
4344
mongoQueryProvider.CollectionNamespace != null)
4445
{
4546
return (mongoQueryProvider.CollectionNamespace.CollectionName, mongoQueryProvider.PipelineInputSerializer);
4647
}
4748

48-
var message = $"inner expression is not an IMongoQueryable representing a collection";
49+
var message = $"inner expression must be a MongoDB IQueryable against a collection";
4950
throw new ExpressionNotSupportedException(innerExpression, containerExpression, because: message);
5051
}
5152

src/MongoDB.Driver/Linq/Linq3Implementation/Misc/ConvertHelper.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using System.Linq.Expressions;
1919
using MongoDB.Bson;
2020
using MongoDB.Bson.Serialization;
21-
using MongoDB.Bson.Serialization.Options;
2221
using MongoDB.Bson.Serialization.Serializers;
2322

2423
namespace MongoDB.Driver.Linq.Linq3Implementation.Misc
@@ -102,22 +101,6 @@ public static bool IsWideningConvert(Type sourceType, Type targetType)
102101
return __wideningConverts.Contains((sourceType, targetType));
103102
}
104103

105-
public static Expression RemoveConvertToMongoQueryable(Expression expression)
106-
{
107-
if (expression.NodeType == ExpressionType.Convert)
108-
{
109-
var convertExpression = (UnaryExpression)expression;
110-
var convertToType = convertExpression.Type;
111-
if (convertToType.IsGenericType &&
112-
convertToType.GetGenericTypeDefinition() == typeof(IMongoQueryable<>))
113-
{
114-
return convertExpression.Operand;
115-
}
116-
}
117-
118-
throw new ExpressionNotSupportedException(expression);
119-
}
120-
121104
public static Expression RemoveConvertToEnumUnderlyingType(Expression expression)
122105
{
123106
if (expression.NodeType == ExpressionType.Convert)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal abstract class MongoQuery<TOutput>
3131
public abstract Task<IAsyncCursor<TOutput>> ExecuteAsync();
3232
}
3333

34-
internal class MongoQuery<TDocument, TOutput> : MongoQuery<TOutput>, IOrderedMongoQueryable<TOutput>, IMongoQueryableForwarder<TOutput>
34+
internal class MongoQuery<TDocument, TOutput> : MongoQuery<TOutput>, IOrderedQueryable<TOutput>, IAsyncCursorSource<TOutput>, IMongoQueryableForwarder<TOutput>
3535
{
3636
// private fields
3737
private readonly Expression _expression;

0 commit comments

Comments
 (0)