Skip to content

Commit 8f4dc64

Browse files
committed
made DeprecatedQuery Obsolete. removed and, not, nor, and or operators from the static Query<T> class as they are merely more verbose versions of the same in the Query class. removed overloads for Matches in the Query class.
1 parent 6386901 commit 8f4dc64

File tree

5 files changed

+39
-233
lines changed

5 files changed

+39
-233
lines changed

Driver/Builders/DeprecatedQueryBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ namespace MongoDB.Driver.Builders
2828
/// <summary>
2929
/// A builder for creating queries.
3030
/// </summary>
31+
[Obsolete("There are 2 new classes used for building queries. MongoDB.Driver.Builders.Query and MongoDB.Driver.Builders.Query<T>")]
3132
public static class DeprecatedQuery
3233
{
3334
// public static properties
@@ -772,6 +773,7 @@ private static void PromoteQueryToDollarAndForm(BsonDocument query, BsonElement
772773
/// A builder for creating queries.
773774
/// </summary>
774775
[Serializable]
776+
[Obsolete("This class has been replaced by MongoDB.Driver.Builders.Query")]
775777
public abstract class DeprecatedQueryBuilder : BuilderBase
776778
{
777779
// private fields
@@ -826,6 +828,7 @@ protected override void Serialize(BsonWriter bsonWriter, Type nominalType, IBson
826828
/// A builder for creating queries.
827829
/// </summary>
828830
[Serializable]
831+
[Obsolete("This class has been replaced by MongoDB.Driver.Builders.Query")]
829832
public class QueryComplete : DeprecatedQueryBuilder, IMongoQuery
830833
{
831834
// constructors
@@ -843,6 +846,7 @@ public QueryComplete(BsonDocument document)
843846
/// A builder for creating queries.
844847
/// </summary>
845848
[Serializable]
849+
[Obsolete("This class has been replaced by MongoDB.Driver.Builders.Query")]
846850
public class QueryConditionList : QueryComplete
847851
{
848852
// private fields
@@ -1247,6 +1251,7 @@ public QueryConditionList WithinRectangle(
12471251
/// <summary>
12481252
/// A builder for creating queries.
12491253
/// </summary>
1254+
[Obsolete("This class has been replaced by MongoDB.Driver.Builders.Query")]
12501255
public class QueryNot
12511256
{
12521257
// private fields
@@ -1537,6 +1542,7 @@ public QueryNotConditionList Type(BsonType type)
15371542
/// A builder for creating queries.
15381543
/// </summary>
15391544
[Serializable]
1545+
[Obsolete("This class has been replaced by MongoDB.Driver.Builders.Query")]
15401546
public class QueryNotConditionList : QueryComplete
15411547
{
15421548
// private fields

Driver/Builders/QueryBuilder.cs

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
namespace MongoDB.Driver.Builders
2525
{
26+
/// <summary>
27+
/// A builder for creating queries.
28+
/// </summary>
2629
public static class Query
2730
{
2831
// public static properties
@@ -274,71 +277,6 @@ public static IMongoQuery Matches(string name, BsonRegularExpression regex)
274277
return new QueryDocument(name, regex);
275278
}
276279

277-
/// <summary>
278-
/// Tests that the value of the named element matches a regular expression (see $regex).
279-
/// </summary>
280-
/// <param name="name">The name of the element to test.</param>
281-
/// <param name="pattern">The pattern.</param>
282-
/// <returns>An IMongoQuery.</returns>
283-
public static IMongoQuery Matches(string name, string pattern)
284-
{
285-
if (name == null)
286-
{
287-
throw new ArgumentNullException("name");
288-
}
289-
if (pattern == null)
290-
{
291-
throw new ArgumentNullException("pattern");
292-
}
293-
294-
return new QueryDocument(name, new BsonRegularExpression(pattern));
295-
}
296-
297-
/// <summary>
298-
/// Tests that the value of the named element matches a regular expression (see $regex).
299-
/// </summary>
300-
/// <param name="name">The name of the element to test.</param>
301-
/// <param name="pattern">The pattern.</param>
302-
/// <param name="options">The options.</param>
303-
/// <returns>An IMongoQuery.</returns>
304-
public static IMongoQuery Matches(string name, string pattern, string options)
305-
{
306-
if (name == null)
307-
{
308-
throw new ArgumentNullException("name");
309-
}
310-
if (pattern == null)
311-
{
312-
throw new ArgumentNullException("pattern");
313-
}
314-
if (options == null)
315-
{
316-
throw new ArgumentNullException("options");
317-
}
318-
319-
return new QueryDocument(name, new BsonRegularExpression(pattern, options));
320-
}
321-
322-
/// <summary>
323-
/// Tests that the value of the named element matches a regular expression (see $regex).
324-
/// </summary>
325-
/// <param name="name">The name of the element to test.</param>
326-
/// <param name="regex">The regex.</param>
327-
/// <returns>An IMongoQuery.</returns>
328-
public static IMongoQuery Matches(string name, Regex regex)
329-
{
330-
if (name == null)
331-
{
332-
throw new ArgumentNullException("name");
333-
}
334-
if (regex == null)
335-
{
336-
throw new ArgumentNullException("regex");
337-
}
338-
339-
return new QueryDocument(name, new BsonRegularExpression(regex));
340-
}
341-
342280
/// <summary>
343281
/// Tests that the modulus of the value of the named element matches some value (see $mod).
344282
/// </summary>
@@ -560,7 +498,7 @@ public static IMongoQuery Or(IEnumerable<IMongoQuery> queries)
560498
switch (queryArray.Count)
561499
{
562500
case 0:
563-
return new QueryComplete(new QueryDocument()); // all queries were empty queries so just return an empty query
501+
return new QueryDocument(); // all queries were empty so just return an empty query
564502
case 1:
565503
return new QueryDocument(queryArray[0].AsBsonDocument);
566504
default:

Driver/Builders/QueryBuilderTyped.cs

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -46,26 +46,6 @@ public static IMongoQuery All<TValue>(Expression<Func<TDocument, IEnumerable<TVa
4646
return new QueryBuilder<TDocument>().All(memberExpression, values);
4747
}
4848

49-
/// <summary>
50-
/// Tests that all the queries are true (see $and in newer versions of the server).
51-
/// </summary>
52-
/// <param name="queries">A list of subqueries.</param>
53-
/// <returns>An IMongoQuery.</returns>
54-
public static IMongoQuery And(IEnumerable<IMongoQuery> queries)
55-
{
56-
return new QueryBuilder<TDocument>().And(queries);
57-
}
58-
59-
/// <summary>
60-
/// Tests that all the queries are true (see $and in newer versions of the server).
61-
/// </summary>
62-
/// <param name="queries">A list of subqueries.</param>
63-
/// <returns>An IMongoQuery.</returns>
64-
public static IMongoQuery And(params IMongoQuery[] queries)
65-
{
66-
return new QueryBuilder<TDocument>().And(queries);
67-
}
68-
6949
/// <summary>
7050
/// Tests that at least one item of the named array element matches a query (see $elemMatch).
7151
/// </summary>
@@ -161,19 +141,6 @@ public static IMongoQuery LTE<TMember>(Expression<Func<TDocument, TMember>> memb
161141
return new QueryBuilder<TDocument>().LTE(memberExpression, value);
162142
}
163143

164-
/// <summary>
165-
/// Tests that the value of the named element matches a regular expression (see $regex).
166-
/// </summary>
167-
/// <param name="memberExpression">The member expression representing the element to test.</param>
168-
/// <param name="regex">The regex.</param>
169-
/// <returns>
170-
/// A query.
171-
/// </returns>
172-
public static IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpression, BsonRegularExpression regex)
173-
{
174-
return new QueryBuilder<TDocument>().Matches(memberExpression, regex);
175-
}
176-
177144
/// <summary>
178145
/// Tests that the value of the named element matches a regular expression (see $regex).
179146
/// </summary>
@@ -187,20 +154,6 @@ public static IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpr
187154
return new QueryBuilder<TDocument>().Matches(memberExpression, pattern);
188155
}
189156

190-
/// <summary>
191-
/// Tests that the value of the named element matches a regular expression (see $regex).
192-
/// </summary>
193-
/// <param name="memberExpression">The member expression representing the element to test.</param>
194-
/// <param name="pattern">The pattern.</param>
195-
/// <param name="options">The options.</param>
196-
/// <returns>
197-
/// A query.
198-
/// </returns>
199-
public static IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpression, string pattern, string options)
200-
{
201-
return new QueryBuilder<TDocument>().Matches(memberExpression, pattern, options);
202-
}
203-
204157
/// <summary>
205158
/// Tests that the value of the named element matches a regular expression (see $regex).
206159
/// </summary>
@@ -268,16 +221,6 @@ public static IMongoQuery Near<TMember>(Expression<Func<TDocument, TMember>> mem
268221
return new QueryBuilder<TDocument>().Near(memberExpression, x, y, maxDistance, spherical);
269222
}
270223

271-
/// <summary>
272-
/// Tests that the inverse of the query is true (see $not).
273-
/// </summary>
274-
/// <param name="query">The query.</param>
275-
/// <returns></returns>
276-
public static IMongoQuery Not(IMongoQuery query)
277-
{
278-
return new QueryBuilder<TDocument>().Not(query);
279-
}
280-
281224
/// <summary>
282225
/// Tests that an element does not equal the value (see $ne).
283226
/// </summary>
@@ -313,30 +256,6 @@ public static IMongoQuery NotIn<TValue>(Expression<Func<TDocument, IEnumerable<T
313256
return new QueryBuilder<TDocument>().NotIn(memberExpression, values);
314257
}
315258

316-
/// <summary>
317-
/// Tests that at least one of the subqueries is true (see $or).
318-
/// </summary>
319-
/// <param name="queries">The subqueries.</param>
320-
/// <returns>
321-
/// A query.
322-
/// </returns>
323-
public static IMongoQuery Or(IEnumerable<IMongoQuery> queries)
324-
{
325-
return new QueryBuilder<TDocument>().Or(queries);
326-
}
327-
328-
/// <summary>
329-
/// Tests that at least one of the subqueries is true (see $or).
330-
/// </summary>
331-
/// <param name="queries">The subqueries.</param>
332-
/// <returns>
333-
/// A query.
334-
/// </returns>
335-
public static IMongoQuery Or(params IMongoQuery[] queries)
336-
{
337-
return new QueryBuilder<TDocument>().Or(queries);
338-
}
339-
340259
/// <summary>
341260
/// Tests that the size of the named array is equal to some value (see $size).
342261
/// </summary>
@@ -361,18 +280,6 @@ public static IMongoQuery Type<TMember>(Expression<Func<TDocument, TMember>> mem
361280
return new QueryBuilder<TDocument>().Type(memberExpression, type);
362281
}
363282

364-
/// <summary>
365-
/// Tests that a JavaScript expression is true (see $where).
366-
/// </summary>
367-
/// <param name="javascript">The javascript.</param>
368-
/// <returns>
369-
/// A query.
370-
/// </returns>
371-
public static IMongoQuery Where(BsonJavaScript javascript)
372-
{
373-
return new QueryBuilder<TDocument>().Where(javascript);
374-
}
375-
376283
/// <summary>
377284
/// Builds a query from an expression.
378285
/// </summary>
@@ -618,20 +525,6 @@ public IMongoQuery LTE<TMember>(Expression<Func<TDocument, TMember>> memberExpre
618525
return Query.LTE(serializationInfo.ElementName, serializedValue);
619526
}
620527

621-
/// <summary>
622-
/// Tests that the value of the named element matches a regular expression (see $regex).
623-
/// </summary>
624-
/// <param name="memberExpression">The member expression representing the element to test.</param>
625-
/// <param name="regex">The regex.</param>
626-
/// <returns>
627-
/// A query.
628-
/// </returns>
629-
public IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpression, BsonRegularExpression regex)
630-
{
631-
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(memberExpression);
632-
return Query.Matches(serializationInfo.ElementName, regex);
633-
}
634-
635528
/// <summary>
636529
/// Tests that the value of the named element matches a regular expression (see $regex).
637530
/// </summary>
@@ -646,21 +539,6 @@ public IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpression,
646539
return Query.Matches(serializationInfo.ElementName, pattern);
647540
}
648541

649-
/// <summary>
650-
/// Tests that the value of the named element matches a regular expression (see $regex).
651-
/// </summary>
652-
/// <param name="memberExpression">The member expression representing the element to test.</param>
653-
/// <param name="pattern">The pattern.</param>
654-
/// <param name="options">The options.</param>
655-
/// <returns>
656-
/// A query.
657-
/// </returns>
658-
public IMongoQuery Matches(Expression<Func<TDocument, string>> memberExpression, string pattern, string options)
659-
{
660-
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(memberExpression);
661-
return Query.Matches(serializationInfo.ElementName, pattern, options);
662-
}
663-
664542
/// <summary>
665543
/// Tests that the value of the named element matches a regular expression (see $regex).
666544
/// </summary>

Driver/Linq/Translators/PredicateTranslator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ private IMongoQuery BuildStringIndexOfQuery(Expression variableExpression, Expre
920920

921921
if (pattern != null)
922922
{
923-
return Query.Matches(serializationInfo.ElementName, pattern, "s");
923+
return Query.Matches(serializationInfo.ElementName, new BsonRegularExpression(pattern, "s"));
924924
}
925925
}
926926

@@ -997,7 +997,7 @@ private IMongoQuery BuildStringIndexQuery(Expression variableExpression, Express
997997
var pattern = string.Format("^.{{{0}}}{1}", index, characterClass);
998998

999999
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(stringExpression);
1000-
return Query.Matches(serializationInfo.ElementName, pattern, "s");
1000+
return Query.Matches(serializationInfo.ElementName, new BsonRegularExpression(pattern, "s"));
10011001
}
10021002

10031003
private IMongoQuery BuildStringLengthQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)
@@ -1234,7 +1234,7 @@ private IMongoQuery BuildStringQuery(MethodCallExpression methodCallExpression)
12341234

12351235
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(stringExpression);
12361236
var options = caseInsensitive ? "is" : "s";
1237-
return Query.Matches(serializationInfo.ElementName, pattern, options);
1237+
return Query.Matches(serializationInfo.ElementName, new BsonRegularExpression(pattern, options));
12381238
}
12391239

12401240
private IMongoQuery BuildTypeComparisonQuery(Expression variableExpression, ExpressionType operatorType, ConstantExpression constantExpression)

0 commit comments

Comments
 (0)