1 //---------------------------------------------------------------------
2 // <copyright file="OperatorExpressions.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
11 using System.Collections.Generic;
12 using System.Diagnostics;
13 using System.Globalization;
15 using System.Data.Common;
16 using System.Data.Metadata.Edm;
17 using System.Data.Common.CommandTrees.Internal;
19 namespace System.Data.Common.CommandTrees
21 #region Boolean Operators
23 /// Represents the logical And of two Boolean arguments.
25 /// <remarks>DbAndExpression requires that both of its arguments have a Boolean result type</remarks>
26 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
27 public sealed class DbAndExpression : DbBinaryExpression
29 internal DbAndExpression(TypeUsage booleanResultType, DbExpression left, DbExpression right)
30 : base(DbExpressionKind.And, booleanResultType, left, right)
32 Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbAndExpression requires a Boolean result type");
36 /// The visitor pattern method for expression visitors that do not produce a result value.
38 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
39 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
40 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
43 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
45 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
46 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
47 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
48 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
49 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
53 /// Represents the logical Or of two Boolean arguments.
55 /// <remarks>DbOrExpression requires that both of its arguments have a Boolean result type</remarks>
56 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
57 public sealed class DbOrExpression : DbBinaryExpression
59 internal DbOrExpression(TypeUsage booleanResultType, DbExpression left, DbExpression right)
60 : base(DbExpressionKind.Or, booleanResultType, left, right)
62 Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbOrExpression requires a Boolean result type");
66 /// The visitor pattern method for expression visitors that do not produce a result value.
68 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
69 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
70 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
73 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
75 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
76 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
77 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
78 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
79 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
83 /// Represents the logical Not of a single Boolean argument.
85 /// <remarks>DbNotExpression requires that its argument has a Boolean result type</remarks>
86 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
87 public sealed class DbNotExpression : DbUnaryExpression
89 internal DbNotExpression(TypeUsage booleanResultType, DbExpression argument)
90 : base(DbExpressionKind.Not, booleanResultType, argument)
92 Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbNotExpression requires a Boolean result type");
96 /// The visitor pattern method for expression visitors that do not produce a result value.
98 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
99 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
100 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
103 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
105 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
106 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
107 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
108 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
109 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
114 /// Represents an arithmetic operation (addition, subtraction, multiplication, division, modulo or negation) applied to two numeric arguments.
116 /// <remarks>DbArithmeticExpression requires that its arguments have a common numeric result type</remarks>
117 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
118 public sealed class DbArithmeticExpression : DbExpression
120 private readonly DbExpressionList _args;
122 internal DbArithmeticExpression(DbExpressionKind kind, TypeUsage numericResultType, DbExpressionList args)
123 : base(kind, numericResultType)
125 Debug.Assert(TypeSemantics.IsNumericType(numericResultType), "DbArithmeticExpression result type must be numeric");
128 DbExpressionKind.Divide == kind ||
129 DbExpressionKind.Minus == kind ||
130 DbExpressionKind.Modulo == kind ||
131 DbExpressionKind.Multiply == kind ||
132 DbExpressionKind.Plus == kind ||
133 DbExpressionKind.UnaryMinus == kind,
134 "Invalid DbExpressionKind used in DbArithmeticExpression: " + Enum.GetName(typeof(DbExpressionKind), kind)
137 Debug.Assert(args != null, "DbArithmeticExpression arguments cannot be null");
140 (DbExpressionKind.UnaryMinus == kind && 1 == args.Count) ||
142 "Incorrect number of arguments specified to DbArithmeticExpression"
149 /// Gets the list of expressions that define the current arguments.
152 /// The <code>Arguments</code> property returns a fixed-size list of <see cref="DbExpression"/> elements.
153 /// <see cref="DbArithmeticExpression"/> requires that all elements of it's <code>Arguments</code> list
154 /// have a common numeric result type.
156 public IList<DbExpression> Arguments { get { return _args; } }
159 /// The visitor pattern method for expression visitors that do not produce a result value.
161 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
162 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
163 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
166 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
168 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
169 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
170 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
171 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
172 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
176 /// Represents a Case When...Then...Else logical operation.
178 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
179 public sealed class DbCaseExpression : DbExpression
181 private readonly DbExpressionList _when;
182 private readonly DbExpressionList _then;
183 private readonly DbExpression _else;
185 internal DbCaseExpression(TypeUsage commonResultType, DbExpressionList whens, DbExpressionList thens, DbExpression elseExpr)
186 : base(DbExpressionKind.Case, commonResultType)
188 Debug.Assert(whens != null, "DbCaseExpression whens cannot be null");
189 Debug.Assert(thens != null, "DbCaseExpression thens cannot be null");
190 Debug.Assert(elseExpr != null, "DbCaseExpression else cannot be null");
191 Debug.Assert(whens.Count == thens.Count, "DbCaseExpression whens count must match thens count");
195 this._else = elseExpr;
199 /// Gets the When clauses of this DbCaseExpression.
201 public IList<DbExpression> When { get { return _when; } }
204 /// Gets the Then clauses of this DbCaseExpression.
206 public IList<DbExpression> Then { get { return _then; } }
209 /// Gets the Else clause of this DbCaseExpression.
211 public DbExpression Else { get { return _else; } }
214 /// The visitor pattern method for expression visitors that do not produce a result value.
216 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
217 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
218 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
221 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
223 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
224 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
225 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
226 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
227 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
231 /// Represents a cast operation applied to a polymorphic argument.
233 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
234 public sealed class DbCastExpression : DbUnaryExpression
236 internal DbCastExpression(TypeUsage type, DbExpression argument)
237 : base(DbExpressionKind.Cast, type, argument)
239 Debug.Assert(TypeSemantics.IsCastAllowed(argument.ResultType, type), "DbCastExpression represents an invalid cast");
243 /// The visitor pattern method for expression visitors that do not produce a result value.
245 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
246 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
247 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
250 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
252 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
253 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
254 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
255 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
256 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
260 /// Represents a comparison operation (equality, greater than, greather than or equal, less than, less than or equal, inequality) applied to two arguments.
263 /// DbComparisonExpression requires that its arguments have a common result type
264 /// that is equality comparable (for <see cref="DbExpressionKind"/>.Equals and <see cref="DbExpressionKind"/>.NotEquals),
265 /// order comparable (for <see cref="DbExpressionKind"/>.GreaterThan and <see cref="DbExpressionKind"/>.LessThan),
266 /// or both (for <see cref="DbExpressionKind"/>.GreaterThanOrEquals and <see cref="DbExpressionKind"/>.LessThanOrEquals).
268 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
269 public sealed class DbComparisonExpression : DbBinaryExpression
271 internal DbComparisonExpression(DbExpressionKind kind, TypeUsage booleanResultType, DbExpression left, DbExpression right)
272 : base(kind, booleanResultType, left, right)
274 Debug.Assert(left != null, "DbComparisonExpression left cannot be null");
275 Debug.Assert(right != null, "DbComparisonExpression right cannot be null");
276 Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbComparisonExpression result type must be a Boolean type");
278 DbExpressionKind.Equals == kind ||
279 DbExpressionKind.LessThan == kind ||
280 DbExpressionKind.LessThanOrEquals == kind ||
281 DbExpressionKind.GreaterThan == kind ||
282 DbExpressionKind.GreaterThanOrEquals == kind ||
283 DbExpressionKind.NotEquals == kind,
284 "Invalid DbExpressionKind used in DbComparisonExpression: " + Enum.GetName(typeof(DbExpressionKind), kind)
289 /// The visitor pattern method for expression visitors that do not produce a result value.
291 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
292 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
293 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
296 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
298 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
299 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
300 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
301 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
302 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
306 /// Represents empty set determination applied to a single set argument.
308 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
309 public sealed class DbIsEmptyExpression : DbUnaryExpression
311 internal DbIsEmptyExpression(TypeUsage booleanResultType, DbExpression argument)
312 : base(DbExpressionKind.IsEmpty, booleanResultType, argument)
314 Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbIsEmptyExpression requires a Boolean result type");
318 /// The visitor pattern method for expression visitors that do not produce a result value.
320 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
321 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
322 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
325 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
327 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
328 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
329 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
330 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
331 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
335 /// Represents null determination applied to a single argument.
337 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
338 public sealed class DbIsNullExpression : DbUnaryExpression
340 internal DbIsNullExpression(TypeUsage booleanResultType, DbExpression arg, bool isRowTypeArgumentAllowed)
341 : base(DbExpressionKind.IsNull, booleanResultType, arg)
343 Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbIsNullExpression requires a Boolean result type");
347 /// The visitor pattern method for expression visitors that do not produce a result value.
349 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
350 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
351 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
354 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
356 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
357 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
358 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
359 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
360 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
364 /// Represents the type comparison of a single argument against the specified type.
366 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
367 public sealed class DbIsOfExpression : DbUnaryExpression
369 private TypeUsage _ofType;
371 internal DbIsOfExpression(DbExpressionKind isOfKind, TypeUsage booleanResultType, DbExpression argument, TypeUsage isOfType)
372 : base(isOfKind, booleanResultType, argument)
374 Debug.Assert(DbExpressionKind.IsOf == this.ExpressionKind || DbExpressionKind.IsOfOnly == this.ExpressionKind, string.Format(CultureInfo.InvariantCulture, "Invalid DbExpressionKind used in DbIsOfExpression: {0}", Enum.GetName(typeof(DbExpressionKind), this.ExpressionKind)));
375 Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbIsOfExpression requires a Boolean result type");
377 this._ofType = isOfType;
381 /// Gets the type metadata that the type metadata of the argument should be compared to.
383 public TypeUsage OfType
385 get { return _ofType; }
389 /// The visitor pattern method for expression visitors that do not produce a result value.
391 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
392 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
393 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
396 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
398 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
399 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
400 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
401 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
402 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
406 /// Represents the retrieval of elements of the specified type from the given set argument.
408 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
409 public sealed class DbOfTypeExpression : DbUnaryExpression
411 private readonly TypeUsage _ofType;
413 internal DbOfTypeExpression(DbExpressionKind ofTypeKind, TypeUsage collectionResultType, DbExpression argument, TypeUsage type)
414 : base(ofTypeKind, collectionResultType, argument)
416 Debug.Assert(DbExpressionKind.OfType == ofTypeKind ||
417 DbExpressionKind.OfTypeOnly == ofTypeKind,
418 "ExpressionKind for DbOfTypeExpression must be OfType or OfTypeOnly");
421 // Assign the requested element type to the OfType property.
427 /// Gets the metadata of the type of elements that should be retrieved from the set argument.
429 public TypeUsage OfType
431 get { return _ofType; }
435 /// The visitor pattern method for expression visitors that do not produce a result value.
437 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
438 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
439 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
442 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
444 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
445 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
446 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
447 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
448 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
452 /// Represents the type conversion of a single argument to the specified type.
454 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
455 public sealed class DbTreatExpression : DbUnaryExpression
457 internal DbTreatExpression(TypeUsage asType, DbExpression argument)
458 : base(DbExpressionKind.Treat, asType, argument)
460 Debug.Assert(TypeSemantics.IsValidPolymorphicCast(argument.ResultType, asType), "DbTreatExpression represents an invalid treat");
464 /// The visitor pattern method for expression visitors that do not produce a result value.
466 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
467 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
468 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
471 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
473 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
474 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
475 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
476 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
477 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
481 /// Represents a string comparison against the specified pattern with an optional escape string
483 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
484 public sealed class DbLikeExpression : DbExpression
486 private readonly DbExpression _argument;
487 private readonly DbExpression _pattern;
488 private readonly DbExpression _escape;
490 internal DbLikeExpression(TypeUsage booleanResultType, DbExpression input, DbExpression pattern, DbExpression escape)
491 : base(DbExpressionKind.Like, booleanResultType)
493 Debug.Assert(input != null, "DbLikeExpression argument cannot be null");
494 Debug.Assert(pattern != null, "DbLikeExpression pattern cannot be null");
495 Debug.Assert(escape != null, "DbLikeExpression escape cannot be null");
496 Debug.Assert(TypeSemantics.IsPrimitiveType(input.ResultType, PrimitiveTypeKind.String), "DbLikeExpression argument must have a string result type");
497 Debug.Assert(TypeSemantics.IsPrimitiveType(pattern.ResultType, PrimitiveTypeKind.String), "DbLikeExpression pattern must have a string result type");
498 Debug.Assert(TypeSemantics.IsPrimitiveType(escape.ResultType, PrimitiveTypeKind.String), "DbLikeExpression escape must have a string result type");
499 Debug.Assert(TypeSemantics.IsBooleanType(booleanResultType), "DbLikeExpression must have a Boolean result type");
501 this._argument = input;
502 this._pattern = pattern;
503 this._escape = escape;
507 /// Gets the expression that specifies the string to compare against the given pattern
509 public DbExpression Argument { get { return _argument; } }
512 /// Gets the expression that specifies the pattern against which the given string should be compared
514 public DbExpression Pattern { get { return _pattern; } }
517 /// Gets the expression that provides an optional escape string to use for the comparison
519 public DbExpression Escape { get { return _escape; } }
522 /// The visitor pattern method for expression visitors that do not produce a result value.
524 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
525 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
526 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
529 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
531 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
532 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
533 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
534 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
535 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
539 /// Represents the retrieval of a reference to the specified Entity as a Ref.
541 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
542 public sealed class DbEntityRefExpression : DbUnaryExpression
544 internal DbEntityRefExpression(TypeUsage refResultType, DbExpression entity)
545 : base(DbExpressionKind.EntityRef, refResultType, entity)
547 Debug.Assert(TypeSemantics.IsReferenceType(refResultType), "DbEntityRefExpression requires a reference result type");
551 /// The visitor pattern method for expression visitors that do not produce a result value.
553 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
554 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
555 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
558 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
560 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
561 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
562 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
563 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
564 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
568 /// Represents the retrieval of the key value of the specified Reference as a row.
570 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
571 public sealed class DbRefKeyExpression : DbUnaryExpression
573 internal DbRefKeyExpression(TypeUsage rowResultType, DbExpression reference)
574 : base(DbExpressionKind.RefKey, rowResultType, reference)
576 Debug.Assert(TypeSemantics.IsRowType(rowResultType), "DbRefKeyExpression requires a row result type");
580 /// The visitor pattern method for expression visitors that do not produce a result value.
582 /// <param name="visitor">An instance of DbExpressionVisitor.</param>
583 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
584 public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
587 /// The visitor pattern method for expression visitors that produce a result value of a specific type.
589 /// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
590 /// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
591 /// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
592 /// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
593 public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }