1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
|
//---------------------------------------------------------------------
// <copyright file="RelationalExpressions.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Diagnostics;
using System.Data.Common;
using System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees.Internal;
namespace System.Data.Common.CommandTrees
{
/// <summary>
/// Represents an apply operation, which is the invocation of the specified functor for each element in the specified input set.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbApplyExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly DbExpressionBinding _apply;
internal DbApplyExpression(DbExpressionKind applyKind, TypeUsage resultRowCollectionTypeUsage, DbExpressionBinding input, DbExpressionBinding apply)
: base(applyKind, resultRowCollectionTypeUsage)
{
Debug.Assert(input != null, "DbApplyExpression input cannot be null");
Debug.Assert(input != null, "DbApplyExpression apply cannot be null");
Debug.Assert(DbExpressionKind.CrossApply == applyKind || DbExpressionKind.OuterApply == applyKind, "Invalid DbExpressionKind for DbApplyExpression");
_input = input;
_apply = apply;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the functor that is invoked for each element in the input set.
/// </summary>
public DbExpressionBinding Apply { get { return _apply; } }
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the removal of duplicate elements from the specified set operand.
/// </summary>
/// <remarks>
/// DbDistinctExpression requires that its argument has a collection result type
/// with an element type that is equality comparable.
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbDistinctExpression : DbUnaryExpression
{
internal DbDistinctExpression(TypeUsage resultType, DbExpression argument)
: base(DbExpressionKind.Distinct, resultType, argument)
{
Debug.Assert(TypeSemantics.IsCollectionType(argument.ResultType), "DbDistinctExpression argument must have a collection result type");
}
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the conversion of the specified set operand to a singleton.
/// If the set is empty the conversion will return null, otherwise the conversion will return one of the elements in the set.
/// </summary>
/// <remarks>
/// DbElementExpression requires that its argument has a collection result type
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbElementExpression : DbUnaryExpression
{
private bool _singlePropertyUnwrapped;
internal DbElementExpression(TypeUsage resultType, DbExpression argument)
: base(DbExpressionKind.Element, resultType, argument)
{
this._singlePropertyUnwrapped = false;
}
internal DbElementExpression(TypeUsage resultType, DbExpression argument, bool unwrapSingleProperty)
: base(DbExpressionKind.Element, resultType, argument)
{
this._singlePropertyUnwrapped = unwrapSingleProperty;
}
/// <summary>
/// Is the result type of the element equal to the result type of the single property
/// of the element of its operand?
/// </summary>
internal bool IsSinglePropertyUnwrapped { get { return _singlePropertyUnwrapped; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the set subtraction operation between the left and right operands.
/// </summary>
/// <remarks>
/// DbExceptExpression requires that its arguments have a common collection result type
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbExceptExpression : DbBinaryExpression
{
internal DbExceptExpression(TypeUsage resultType, DbExpression left, DbExpression right)
: base(DbExpressionKind.Except, resultType, left, right)
{
Debug.Assert(object.ReferenceEquals(resultType, left.ResultType), "DbExceptExpression result type should be result type of left argument");
}
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents a predicate applied to an input set to produce the set of elements that satisfy the predicate.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbFilterExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly DbExpression _predicate;
internal DbFilterExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression predicate)
: base(DbExpressionKind.Filter, resultType)
{
Debug.Assert(input != null, "DbFilterExpression input cannot be null");
Debug.Assert(predicate != null, "DbBFilterExpression predicate cannot be null");
Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbFilterExpression predicate must have a Boolean result type");
_input = input;
_predicate = predicate;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets the <see cref="DbExpression"/> that specifies the predicate used to filter the input set.
/// </summary>
public DbExpression Predicate { get { return _predicate; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// 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.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbGroupByExpression : DbExpression
{
private readonly DbGroupExpressionBinding _input;
private readonly DbExpressionList _keys;
private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbAggregate> _aggregates;
internal DbGroupByExpression(TypeUsage collectionOfRowResultType,
DbGroupExpressionBinding input,
DbExpressionList groupKeys,
System.Collections.ObjectModel.ReadOnlyCollection<DbAggregate> aggregates)
: base(DbExpressionKind.GroupBy, collectionOfRowResultType)
{
Debug.Assert(input != null, "DbGroupExpression input cannot be null");
Debug.Assert(groupKeys != null, "DbGroupExpression keys cannot be null");
Debug.Assert(aggregates != null, "DbGroupExpression aggregates cannot be null");
Debug.Assert(groupKeys.Count > 0 || aggregates.Count > 0, "At least one key or aggregate is required");
_input = input;
_keys = groupKeys;
_aggregates = aggregates;
}
/// <summary>
/// Gets the <see cref="DbGroupExpressionBinding"/> that specifies the input set and provides access to the set element and group element variables.
/// </summary>
public DbGroupExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets an <see cref="DbExpression"/> list that provides grouping keys.
/// </summary>
public IList<DbExpression> Keys { get { return _keys; } }
/// <summary>
/// Gets an <see cref="DbAggregate"/> list that provides the aggregates to apply.
/// </summary>
public IList<DbAggregate> Aggregates { get { return _aggregates; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the set intersection operation between the left and right operands.
/// </summary>
/// <remarks>
/// DbIntersectExpression requires that its arguments have a common collection result type
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbIntersectExpression : DbBinaryExpression
{
internal DbIntersectExpression(TypeUsage resultType, DbExpression left, DbExpression right)
: base(DbExpressionKind.Intersect, resultType, left, right)
{
}
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents an unconditional join operation between the given collection arguments
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbCrossJoinExpression : DbExpression
{
private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbExpressionBinding> _inputs;
internal DbCrossJoinExpression(TypeUsage collectionOfRowResultType, System.Collections.ObjectModel.ReadOnlyCollection<DbExpressionBinding> inputs)
: base(DbExpressionKind.CrossJoin, collectionOfRowResultType)
{
Debug.Assert(inputs != null, "DbCrossJoin inputs cannot be null");
Debug.Assert(inputs.Count >= 2, "DbCrossJoin requires at least two inputs");
_inputs = inputs;
}
/// <summary>
/// Gets an <see cref="DbExpressionBinding"/> list that provide the input sets to the join.
/// </summary>
public IList<DbExpressionBinding> Inputs { get { return _inputs; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents an inner, left outer or full outer join operation between the given collection arguments on the specified join condition.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbJoinExpression : DbExpression
{
private readonly DbExpressionBinding _left;
private readonly DbExpressionBinding _right;
private readonly DbExpression _condition;
internal DbJoinExpression(DbExpressionKind joinKind, TypeUsage collectionOfRowResultType, DbExpressionBinding left, DbExpressionBinding right, DbExpression condition)
: base(joinKind, collectionOfRowResultType)
{
Debug.Assert(left != null, "DbJoinExpression left cannot be null");
Debug.Assert(right != null, "DbJoinExpression right cannot be null");
Debug.Assert(condition != null, "DbJoinExpression condition cannot be null");
Debug.Assert(DbExpressionKind.InnerJoin == joinKind ||
DbExpressionKind.LeftOuterJoin == joinKind ||
DbExpressionKind.FullOuterJoin == joinKind,
"Invalid DbExpressionKind specified for DbJoinExpression");
_left = left;
_right = right;
_condition = condition;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> provides the left input.
/// </summary>
public DbExpressionBinding Left { get { return _left; } }
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> provides the right input.
/// </summary>
public DbExpressionBinding Right { get { return _right; } }
/// <summary>
/// Gets the <see cref="DbExpression"/> that defines the join condition to apply.
/// </summary>
public DbExpression JoinCondition { get { return _condition; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the restriction of the number of elements in the Argument collection to the specified Limit value.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbLimitExpression : DbExpression
{
private readonly DbExpression _argument;
private readonly DbExpression _limit;
private readonly bool _withTies;
internal DbLimitExpression(TypeUsage resultType, DbExpression argument, DbExpression limit, bool withTies)
: base(DbExpressionKind.Limit, resultType)
{
Debug.Assert(argument != null, "DbLimitExpression argument cannot be null");
Debug.Assert(limit != null, "DbLimitExpression limit cannot be null");
Debug.Assert(object.ReferenceEquals(resultType, argument.ResultType), "DbLimitExpression result type must be the result type of the argument");
this._argument = argument;
this._limit = limit;
this._withTies = withTies;
}
/// <summary>
/// Gets the expression that specifies the input collection.
/// </summary>
public DbExpression Argument { get { return this._argument; } }
/// <summary>
/// Gets the expression that specifies the limit on the number of elements returned from the input collection.
/// </summary>
public DbExpression Limit { get { return this._limit; } }
/// <summary>
/// Gets whether the limit operation will include tied results, which could produce more results than specifed by the Limit value if ties are present.
/// </summary>
public bool WithTies { get { return _withTies; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the projection of a given set of values over the specified input set.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbProjectExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly DbExpression _projection;
internal DbProjectExpression(TypeUsage resultType, DbExpressionBinding input, DbExpression projection)
: base(DbExpressionKind.Project, resultType)
{
Debug.Assert(input != null, "DbProjectExpression input cannot be null");
Debug.Assert(projection != null, "DbProjectExpression projection cannot be null");
this._input = input;
this._projection = projection;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets the <see cref="DbExpression"/> that defines the projection.
/// </summary>
public DbExpression Projection { get { return _projection; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents a quantifier operation of the specified kind (Any, All) over the elements of the specified input set.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbQuantifierExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly DbExpression _predicate;
internal DbQuantifierExpression(DbExpressionKind kind, TypeUsage booleanResultType, DbExpressionBinding input, DbExpression predicate)
: base(kind, booleanResultType)
{
Debug.Assert(input != null, "DbQuantifierExpression input cannot be null");
Debug.Assert(predicate != null, "DbQuantifierExpression predicate cannot be null");
Debug.Assert(TypeSemantics.IsPrimitiveType(booleanResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression must have a Boolean result type");
Debug.Assert(TypeSemantics.IsPrimitiveType(predicate.ResultType, PrimitiveTypeKind.Boolean), "DbQuantifierExpression predicate must have a Boolean result type");
this._input = input;
this._predicate = predicate;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets the Boolean predicate that should be evaluated for each element in the input set.
/// </summary>
public DbExpression Predicate { get { return _predicate; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Specifies a sort key that can be used as part of the sort order in a DbSortExpression.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbSortClause
{
private readonly DbExpression _expr;
private readonly bool _asc;
private readonly string _coll;
internal DbSortClause(DbExpression key, bool asc, string collation)
{
Debug.Assert(key != null, "DbSortClause key cannot be null");
_expr = key;
_asc = asc;
_coll = collation;
}
/// <summary>
/// Gets a Boolean value indicating whether or not this sort key is sorted ascending.
/// </summary>
public bool Ascending { get { return _asc; } }
/// <summary>
/// Gets a string value that specifies the collation for this sort key.
/// </summary>
public string Collation { get { return _coll; } }
/// <summary>
/// Gets the <see cref="DbExpression"/> that provides the value for this sort key.
/// </summary>
public DbExpression Expression { get { return _expr; } }
}
/// <summary>
/// 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.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbSkipExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> _keys;
private readonly DbExpression _count;
internal DbSkipExpression(TypeUsage resultType, DbExpressionBinding input, System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> sortOrder, DbExpression count)
: base(DbExpressionKind.Skip, resultType)
{
Debug.Assert(input != null, "DbSkipExpression input cannot be null");
Debug.Assert(sortOrder != null, "DbSkipExpression sort order cannot be null");
Debug.Assert(count != null, "DbSkipExpression count cannot be null");
Debug.Assert(TypeSemantics.IsCollectionType(resultType), "DbSkipExpression requires a collection result type");
this._input = input;
this._keys = sortOrder;
this._count = count;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets a <see cref="DbSortClause"/> list that defines the sort order.
/// </summary>
public IList<DbSortClause> SortOrder { get { return _keys; } }
/// <summary>
/// Gets the expression that specifies the number of elements from the input collection to skip.
/// </summary>
public DbExpression Count
{
get { return _count; }
}
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents a sort operation applied to the elements of the specified input set based on the given sort keys.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbSortExpression : DbExpression
{
private readonly DbExpressionBinding _input;
private readonly System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> _keys;
internal DbSortExpression(TypeUsage resultType, DbExpressionBinding input, System.Collections.ObjectModel.ReadOnlyCollection<DbSortClause> sortOrder)
: base(DbExpressionKind.Sort, resultType)
{
Debug.Assert(input != null, "DbSortExpression input cannot be null");
Debug.Assert(sortOrder != null, "DbSortExpression sort order cannot be null");
Debug.Assert(TypeSemantics.IsCollectionType(resultType), "DbSkipExpression requires a collection result type");
this._input = input;
this._keys = sortOrder;
}
/// <summary>
/// Gets the <see cref="DbExpressionBinding"/> that specifies the input set.
/// </summary>
public DbExpressionBinding Input { get { return _input; } }
/// <summary>
/// Gets a <see cref="DbSortClause"/> list that defines the sort order.
/// </summary>
public IList<DbSortClause> SortOrder { get { return _keys; } }
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
/// <summary>
/// Represents the set union (without duplicate removal) operation between the left and right operands.
/// </summary>
/// <remarks>
/// DbUnionAllExpression requires that its arguments have a common collection result type
/// </remarks>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbUnionAllExpression : DbBinaryExpression
{
internal DbUnionAllExpression(TypeUsage resultType, DbExpression left, DbExpression right)
: base(DbExpressionKind.UnionAll, resultType, left, right)
{
}
/// <summary>
/// The visitor pattern method for expression visitors that do not produce a result value.
/// </summary>
/// <param name="visitor">An instance of DbExpressionVisitor.</param>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
public override void Accept(DbExpressionVisitor visitor) { if (visitor != null) { visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
/// <summary>
/// The visitor pattern method for expression visitors that produce a result value of a specific type.
/// </summary>
/// <param name="visitor">An instance of a typed DbExpressionVisitor that produces a result value of type TResultType.</param>
/// <typeparam name="TResultType">The type of the result produced by <paramref name="visitor"/></typeparam>
/// <exception cref="ArgumentNullException"><paramref name="visitor"/> is null</exception>
/// <returns>An instance of <typeparamref name="TResultType"/>.</returns>
public override TResultType Accept<TResultType>(DbExpressionVisitor<TResultType> visitor) { if (visitor != null) { return visitor.Visit(this); } else { throw EntityUtil.ArgumentNull("visitor"); } }
}
}
|