1 //---------------------------------------------------------------------
2 // <copyright file="RelationalExpressions.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Globalization;
13 using System.Diagnostics;
15 using System.Data.Common;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees.Internal;
19 namespace System.Data.Common.CommandTrees
22 /// Represents an apply operation, which is the invocation of the specified functor for each element in the specified input set.
24 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
25 public sealed class DbApplyExpression : DbExpression
27 private readonly DbExpressionBinding _input;
28 private readonly DbExpressionBinding _apply;
30 internal DbApplyExpression(DbExpressionKind applyKind, TypeUsage resultRowCollectionTypeUsage, DbExpressionBinding input, DbExpressionBinding apply)
31 : base(applyKind, resultRowCollectionTypeUsage)
33 Debug.Assert(input != null, "DbApplyExpression input cannot be null");
34 Debug.Assert(input != null, "DbApplyExpression apply cannot be null");
35 Debug.Assert(DbExpressionKind.CrossApply == applyKind || DbExpressionKind.OuterApply == applyKind, "Invalid DbExpressionKind for DbApplyExpression");
42 /// Gets the <see cref="DbExpressionBinding"/> that specifies the functor that is invoked for each element in the input set.
44 public DbExpressionBinding Apply { get { return _apply; } }
47 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
49 public DbExpressionBinding Input { get { return _input; } }
52 /// The visitor pattern method for expression visitors that do not produce a result value.
54 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
55 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
56 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
59 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
61 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
62 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
63 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
64 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
65 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
69 /// Represents the removal of duplicate elements from the specified set operand.
72 /// DbDistinctExpression requires that its argument has a collection result type
73 /// with an element type that is equality comparable.
75 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
76 public sealed class DbDistinctExpression : DbUnaryExpression
78 internal DbDistinctExpression(TypeUsage resultType, DbExpression argument)
79 : base(DbExpressionKind.Distinct, resultType, argument)
81 Debug.Assert(TypeSemantics.IsCollectionType(argument.ResultType), "DbDistinctExpression argument must have a collection result type");
85 /// The visitor pattern method for expression visitors that do not produce a result value.
87 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
88 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
89 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
92 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
94 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
95 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
96 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
97 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
98 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
102 /// Represents the conversion of the specified set operand to a singleton.
103 /// If the set is empty the conversion will return null, otherwise the conversion will return one of the elements in the set.
106 /// DbElementExpression requires that its argument has a collection result type
108 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
109 public sealed class DbElementExpression : DbUnaryExpression
111 private bool _singlePropertyUnwrapped;
113 internal DbElementExpression(TypeUsage resultType, DbExpression argument)
114 : base(DbExpressionKind.Element, resultType, argument)
116 this._singlePropertyUnwrapped = false;
119 internal DbElementExpression(TypeUsage resultType, DbExpression argument, bool unwrapSingleProperty)
120 : base(DbExpressionKind.Element, resultType, argument)
122 this._singlePropertyUnwrapped = unwrapSingleProperty;
126 /// Is the result type of the element equal to the result type of the single property
127 /// of the element of its operand?
129 internal bool IsSinglePropertyUnwrapped { get { return _singlePropertyUnwrapped; } }
132 /// The visitor pattern method for expression visitors that do not produce a result value.
134 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
135 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
136 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
139 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
141 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
142 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
143 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
144 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
145 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
149 /// Represents the set subtraction operation between the left and right operands.
152 /// DbExceptExpression requires that its arguments have a common collection result type
154 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
155 public sealed class DbExceptExpression : DbBinaryExpression
157 internal DbExceptExpression(TypeUsage resultType, DbExpression left, DbExpression right)
158 : base(DbExpressionKind.Except, resultType, left, right)
160 Debug.Assert(object.ReferenceEquals(resultType, left.ResultType), "DbExceptExpression result type should be result type of left argument");
164 /// The visitor pattern method for expression visitors that do not produce a result value.
166 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
167 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
168 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
171 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
173 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
174 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
175 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
176 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
177 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
181 /// Represents a predicate applied to an input set to produce the set of elements that satisfy the predicate.
183 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
184 public sealed class DbFilterExpression : DbExpression
186 private readonly DbExpressionBinding _input;
187 private readonly DbExpression _predicate;
189 internal DbFilterExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression predicate)
190 : base(DbExpressionKind.Filter, resultType)
192 Debug.Assert(input != null, "DbFilterExpression input cannot be null");
193 Debug.Assert(predicate != null, "DbBFilterExpression predicate cannot be null");
194 Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbFilterExpression predicate must have a Boolean result type");
197 _predicate = predicate;
201 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
203 public DbExpressionBinding Input { get { return _input; } }
206 /// Gets the <see cref="DbExpression"/> that specifies the predicate used to filter the input set.
208 public DbExpression Predicate { get { return _predicate; } }
211 /// The visitor pattern method for expression visitors that do not produce a result value.
213 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
214 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
215 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
218 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
220 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
221 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
222 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
223 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
224 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
228 /// Represents a group by operation, which is a grouping of the elements in the input set based on the specified key expressions followed by the application of the specified aggregates.
230 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
231 public sealed class DbGroupByExpression : DbExpression
233 private readonly DbGroupExpressionBinding _input;
234 private readonly DbExpressionList _keys;
235 private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbAggregate> _aggregates;
237 internal DbGroupByExpression(TypeUsage collectionOfRowResultType,
238 DbGroupExpressionBinding input,
239 DbExpressionList groupKeys,
240 System.Collections.ObjectModel.ReadOnlyCollection<DbAggregate> aggregates)
241 : base(DbExpressionKind.GroupBy, collectionOfRowResultType)
243 Debug.Assert(input != null, "DbGroupExpression input cannot be null");
244 Debug.Assert(groupKeys != null, "DbGroupExpression keys cannot be null");
245 Debug.Assert(aggregates != null, "DbGroupExpression aggregates cannot be null");
246 Debug.Assert(groupKeys.Count > 0 || aggregates.Count > 0, "At least one key or aggregate is required");
250 _aggregates = aggregates;
254 /// Gets the <see cref="DbGroupExpressionBinding"/> that specifies the input set and provides access to the set element and group element variables.
256 public DbGroupExpressionBinding Input { get { return _input; } }
259 /// Gets an <see cref="DbExpression"/> list that provides grouping keys.
261 public IList<DbExpression> Keys { get { return _keys; } }
264 /// Gets an <see cref="DbAggregate"/> list that provides the aggregates to apply.
266 public IList<DbAggregate> Aggregates { get { return _aggregates; } }
269 /// The visitor pattern method for expression visitors that do not produce a result value.
271 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
272 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
273 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
276 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
278 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
279 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
280 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
281 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
282 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
286 /// Represents the set intersection operation between the left and right operands.
289 /// DbIntersectExpression requires that its arguments have a common collection result type
291 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
292 public sealed class DbIntersectExpression : DbBinaryExpression
294 internal DbIntersectExpression(TypeUsage resultType, DbExpression left, DbExpression right)
295 : base(DbExpressionKind.Intersect, resultType, left, right)
300 /// The visitor pattern method for expression visitors that do not produce a result value.
302 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
303 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
304 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
307 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
309 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
310 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
311 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
312 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
313 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
317 /// Represents an unconditional join operation between the given collection arguments
319 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
320 public sealed class DbCrossJoinExpression : DbExpression
322 private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbExpressionBinding> _inputs;
324 internal DbCrossJoinExpression(TypeUsage collectionOfRowResultType, System.Collections.ObjectModel.ReadOnlyCollection<DbExpressionBinding> inputs)
325 : base(DbExpressionKind.CrossJoin, collectionOfRowResultType)
327 Debug.Assert(inputs != null, "DbCrossJoin inputs cannot be null");
328 Debug.Assert(inputs.Count >= 2, "DbCrossJoin requires at least two inputs");
334 /// Gets an <see cref="DbExpressionBinding"/> list that provide the input sets to the join.
336 public IList<DbExpressionBinding> Inputs { get { return _inputs; } }
339 /// The visitor pattern method for expression visitors that do not produce a result value.
341 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
342 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
343 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
346 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
348 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
349 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
350 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
351 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
352 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
356 /// Represents an inner, left outer or full outer join operation between the given collection arguments on the specified join condition.
358 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
359 public sealed class DbJoinExpression : DbExpression
361 private readonly DbExpressionBinding _left;
362 private readonly DbExpressionBinding _right;
363 private readonly DbExpression _condition;
365 internal DbJoinExpression(DbExpressionKind joinKind, TypeUsage collectionOfRowResultType, DbExpressionBinding left, DbExpressionBinding right, DbExpression condition)
366 : base(joinKind, collectionOfRowResultType)
368 Debug.Assert(left != null, "DbJoinExpression left cannot be null");
369 Debug.Assert(right != null, "DbJoinExpression right cannot be null");
370 Debug.Assert(condition != null, "DbJoinExpression condition cannot be null");
371 Debug.Assert(DbExpressionKind.InnerJoin == joinKind ||
372 DbExpressionKind.LeftOuterJoin == joinKind ||
373 DbExpressionKind.FullOuterJoin == joinKind,
374 "Invalid DbExpressionKind specified for DbJoinExpression");
378 _condition = condition;
382 /// Gets the <see cref="DbExpressionBinding"/> provides the left input.
384 public DbExpressionBinding Left { get { return _left; } }
387 /// Gets the <see cref="DbExpressionBinding"/> provides the right input.
389 public DbExpressionBinding Right { get { return _right; } }
392 /// Gets the <see cref="DbExpression"/> that defines the join condition to apply.
394 public DbExpression JoinCondition { get { return _condition; } }
397 /// The visitor pattern method for expression visitors that do not produce a result value.
399 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
400 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
401 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
404 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
406 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
407 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
408 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
409 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
410 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
414 /// Represents the restriction of the number of elements in the Argument collection to the specified Limit value.
416 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
417 public sealed class DbLimitExpression : DbExpression
419 private readonly DbExpression _argument;
420 private readonly DbExpression _limit;
421 private readonly bool _withTies;
423 internal DbLimitExpression(TypeUsage resultType, DbExpression argument, DbExpression limit, bool withTies)
424 : base(DbExpressionKind.Limit, resultType)
426 Debug.Assert(argument != null, "DbLimitExpression argument cannot be null");
427 Debug.Assert(limit != null, "DbLimitExpression limit cannot be null");
428 Debug.Assert(object.ReferenceEquals(resultType, argument.ResultType), "DbLimitExpression result type must be the result type of the argument");
430 this._argument = argument;
432 this._withTies = withTies;
436 /// Gets the expression that specifies the input collection.
438 public DbExpression Argument { get { return this._argument; } }
441 /// Gets the expression that specifies the limit on the number of elements returned from the input collection.
443 public DbExpression Limit { get { return this._limit; } }
446 /// Gets whether the limit operation will include tied results, which could produce more results than specifed by the Limit value if ties are present.
448 public bool WithTies { get { return _withTies; } }
451 /// The visitor pattern method for expression visitors that do not produce a result value.
453 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
454 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
455 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
458 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
460 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
461 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
462 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
463 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
464 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
468 /// Represents the projection of a given set of values over the specified input set.
470 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
471 public sealed class DbProjectExpression : DbExpression
473 private readonly DbExpressionBinding _input;
474 private readonly DbExpression _projection;
476 internal DbProjectExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression projection)
477 : base(DbExpressionKind.Project, resultType)
479 Debug.Assert(input != null, "DbProjectExpression input cannot be null");
480 Debug.Assert(projection != null, "DbProjectExpression projection cannot be null");
483 this._projection = projection;
487 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
489 public DbExpressionBinding Input { get { return _input; } }
492 /// Gets the <see cref="DbExpression"/> that defines the projection.
494 public DbExpression Projection { get { return _projection; } }
497 /// The visitor pattern method for expression visitors that do not produce a result value.
499 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
500 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
501 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
504 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
506 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
507 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
508 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
509 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
510 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
514 /// Represents a quantifier operation of the specified kind (Any, All) over the elements of the specified input set.
516 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
517 public sealed class DbQuantifierExpression : DbExpression
519 private readonly DbExpressionBinding _input;
520 private readonly DbExpression _predicate;
522 internal DbQuantifierExpression(DbExpressionKind kind, TypeUsage booleanResultType, DbExpressionBinding input, DbExpression predicate)
523 : base(kind, booleanResultType)
525 Debug.Assert(input != null, "DbQuantifierExpression input cannot be null");
526 Debug.Assert(predicate != null, "DbQuantifierExpression predicate cannot be null");
527 Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression must have a Boolean result type");
528 Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression predicate must have a Boolean result type");
531 this._predicate = predicate;
535 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
537 public DbExpressionBinding Input { get { return _input; } }
540 /// Gets the Boolean predicate that should be evaluated for each element in the input set.
542 public DbExpression Predicate { get { return _predicate; } }
545 /// The visitor pattern method for expression visitors that do not produce a result value.
547 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
548 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
549 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
552 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
554 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
555 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
556 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
557 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
558 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
562 /// Specifies a sort key that can be used as part of the sort order in a DbSortExpression.
564 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
565 public sealed class DbSortClause
567 private readonly DbExpression _expr;
568 private readonly bool _asc;
569 private readonly string _coll;
571 internal DbSortClause(DbExpression key, bool asc, string collation)
573 Debug.Assert(key != null, "DbSortClause key cannot be null");
581 /// Gets a Boolean value indicating whether or not this sort key is sorted ascending.
583 public bool Ascending { get { return _asc; } }
586 /// Gets a string value that specifies the collation for this sort key.
588 public string Collation { get { return _coll; } }
591 /// Gets the <see cref="DbExpression"/> that provides the value for this sort key.
593 public DbExpression Expression { get { return _expr; } }
597 /// Represents a skip operation of the specified number of elements of the input set after the ordering described in the given sort keys is applied.
599 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
600 public sealed class DbSkipExpression : DbExpression
602 private readonly DbExpressionBinding _input;
603 private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> _keys;
604 private readonly DbExpression _count;
606 internal DbSkipExpression(TypeUsage resultType, DbExpressionBinding input, System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> sortOrder, DbExpression count)
607 : base(DbExpressionKind.Skip, resultType)
609 Debug.Assert(input != null, "DbSkipExpression input cannot be null");
610 Debug.Assert(sortOrder != null, "DbSkipExpression sort order cannot be null");
611 Debug.Assert(count != null, "DbSkipExpression count cannot be null");
612 Debug.Assert(TypeSemantics.IsCollectionType(resultType), "DbSkipExpression requires a collection result type");
615 this._keys = sortOrder;
620 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
622 public DbExpressionBinding Input { get { return _input; } }
625 /// Gets a <see cref="DbSortClause"/> list that defines the sort order.
627 public IList<DbSortClause> SortOrder { get { return _keys; } }
630 /// Gets the expression that specifies the number of elements from the input collection to skip.
632 public DbExpression Count
634 get { return _count; }
638 /// The visitor pattern method for expression visitors that do not produce a result value.
640 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
641 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
642 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
645 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
647 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
648 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
649 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
650 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
651 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
655 /// Represents a sort operation applied to the elements of the specified input set based on the given sort keys.
657 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
658 public sealed class DbSortExpression : DbExpression
660 private readonly DbExpressionBinding _input;
661 private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> _keys;
663 internal DbSortExpression(TypeUsage resultType, DbExpressionBinding input, System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> sortOrder)
664 : base(DbExpressionKind.Sort, resultType)
666 Debug.Assert(input != null, "DbSortExpression input cannot be null");
667 Debug.Assert(sortOrder != null, "DbSortExpression sort order cannot be null");
668 Debug.Assert(TypeSemantics.IsCollectionType(resultType), "DbSkipExpression requires a collection result type");
671 this._keys = sortOrder;
675 /// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
677 public DbExpressionBinding Input { get { return _input; } }
680 /// Gets a <see cref="DbSortClause"/> list that defines the sort order.
682 public IList<DbSortClause> SortOrder { get { return _keys; } }
685 /// The visitor pattern method for expression visitors that do not produce a result value.
687 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
688 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
689 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
692 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
694 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
695 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
696 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
697 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
698 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
702 /// Represents the set union (without duplicate removal) operation between the left and right operands.
705 /// DbUnionAllExpression requires that its arguments have a common collection result type
707 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
708 public sealed class DbUnionAllExpression : DbBinaryExpression
710 internal DbUnionAllExpression(TypeUsage resultType, DbExpression left, DbExpression right)
711 : base(DbExpressionKind.UnionAll, resultType, left, right)
716 /// The visitor pattern method for expression visitors that do not produce a result value.
718 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
719 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
720 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
723 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
725 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
726 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
727 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
728 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
729 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }