Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / CommandTrees / Aggregates.cs / 2 / Aggregates.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Data.Common;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees.Internal;
using System.Diagnostics;
namespace System.Data.Common.CommandTrees
{
///
/// Aggregates are pseudo-expressions. They look and feel like expressions, but
/// are severely restricted in where they can appear - only in the aggregates clause
/// of a group-by expression.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public abstract class DbAggregate
{
private DbCommandTree _commandTree;
private ExpressionList _args;
private TypeUsage _type;
internal DbAggregate(DbCommandTree commandTree)
{
_commandTree = EntityUtil.CheckArgumentNull(commandTree, "commandTree");
}
internal ExpressionList ArgumentList { get { return _args; } set { _args = value; } }
///
/// The DbCommandTree with which this DbAggregate is associated
///
internal DbCommandTree CommandTree { get { return _commandTree; } }
///
/// Gets the result type of this aggregate
///
public TypeUsage ResultType
{
get { return _type; }
internal set
{
// this is causing null ref
//Debug.Assert(_type.IsReadOnlyItem, "Editable type specified as DbAggregate.ResultType");
_type = value;
}
}
///
/// Gets the list of expressions that define the arguments to the aggregate.
///
public IList Arguments { get { return _args; } }
}
#if ENABLE_NESTAGGREGATE
///
/// The aggregate type that corresponds to a nesting operation.
///
public sealed class NestAggregate : Aggregate
{
internal NestAggregate(CommandTree commandTree, Expression arg)
: base(commandTree)
{
if (null == arg)
{
throw EntityUtil.ArgumentNull("arg");
}
this.ArgumentList = new ExpressionList("Arguments", commandTree, arg.ResultType, CommandTreeUtils.CreateList(arg));
this.ResultType = commandTree.TypeHelper.CreateCollectionType(arg.Type);
}
}
#endif
///
/// The aggregate type that corresponds to the invocation of an aggregate function.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbFunctionAggregate : DbAggregate
{
private bool _distinct;
EdmFunction _aggregateFunction;
internal DbFunctionAggregate(DbCommandTree commandTree, EdmFunction function, DbExpression arg, bool isDistinct)
: base(commandTree)
{
EntityUtil.CheckArgumentNull(arg, "arg");
_distinct = isDistinct;
//
// Verify that the aggregate function is from the metadata collection and data space of the command tree.
//
commandTree.TypeHelper.CheckFunction(function);
// Verify that the function is actually a valid aggregate function.
// For now, only a single argument is allowed.
if (!TypeSemantics.IsAggregateFunction(function) ||
null == function.ReturnParameter ||
TypeSemantics.IsNullOrNullType(function.ReturnParameter.TypeUsage))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Aggregate_InvalidFunction, "function");
}
_aggregateFunction = function;
// Create an ExpressionList without initializing the expected element types or element values
this.ArgumentList = new ExpressionList("Arguments", commandTree, function.Parameters.Count);
List funcArgs = CommandTreeUtils.CreateList(arg);
//
// Set the expected element type for each element in the ExpressionList based on the parameter
// type of each formal parameter to the function. For each parameter, if its parameter type is
// a collection type then the element type of that collection will be used. Otherwise the parameter
// type itself will be used. This is necessary because aggregate functions may be used outside of
// GroupBy and therefore always specify their parameter types as collection types. From within
// GroupBy the (non-collection) GroupVar may legally be passed to the same aggregate function.
// After the expected element type is set, the element value is set. This causes ExpressionLink type
// checking and other expression validation to occur against the expected element type that was just set.
//
Debug.Assert(funcArgs.Count == function.Parameters.Count, "Incorrect number of arguments specified for DbFunctionAggregate");
for (int idx = 0; idx < funcArgs.Count; idx++)
{
TypeUsage paramType = function.Parameters[idx].TypeUsage;
TypeUsage elementType = null;
if(TypeHelpers.TryGetCollectionElementType(paramType, out elementType))
{
paramType = elementType;
}
this.ArgumentList.ExpressionLinks[idx].SetExpectedType(paramType);
this.ArgumentList.ExpressionLinks[idx].InitializeValue(funcArgs[idx]);
}
this.ResultType = function.ReturnParameter.TypeUsage;
}
///
/// Gets a value indicating whether the aggregate function is applied in a distinct fashion
///
public bool Distinct { get { return _distinct; } }
///
/// Gets the method metadata that specifies the aggregate function to invoke.
///
public EdmFunction Function { get { return _aggregateFunction; } }
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System;
using System.Data.Common;
using System.Collections.Generic;
using System.Data.Metadata.Edm;
using System.Data.Common.CommandTrees.Internal;
using System.Diagnostics;
namespace System.Data.Common.CommandTrees
{
///
/// Aggregates are pseudo-expressions. They look and feel like expressions, but
/// are severely restricted in where they can appear - only in the aggregates clause
/// of a group-by expression.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public abstract class DbAggregate
{
private DbCommandTree _commandTree;
private ExpressionList _args;
private TypeUsage _type;
internal DbAggregate(DbCommandTree commandTree)
{
_commandTree = EntityUtil.CheckArgumentNull(commandTree, "commandTree");
}
internal ExpressionList ArgumentList { get { return _args; } set { _args = value; } }
///
/// The DbCommandTree with which this DbAggregate is associated
///
internal DbCommandTree CommandTree { get { return _commandTree; } }
///
/// Gets the result type of this aggregate
///
public TypeUsage ResultType
{
get { return _type; }
internal set
{
// this is causing null ref
//Debug.Assert(_type.IsReadOnlyItem, "Editable type specified as DbAggregate.ResultType");
_type = value;
}
}
///
/// Gets the list of expressions that define the arguments to the aggregate.
///
public IList Arguments { get { return _args; } }
}
#if ENABLE_NESTAGGREGATE
///
/// The aggregate type that corresponds to a nesting operation.
///
public sealed class NestAggregate : Aggregate
{
internal NestAggregate(CommandTree commandTree, Expression arg)
: base(commandTree)
{
if (null == arg)
{
throw EntityUtil.ArgumentNull("arg");
}
this.ArgumentList = new ExpressionList("Arguments", commandTree, arg.ResultType, CommandTreeUtils.CreateList(arg));
this.ResultType = commandTree.TypeHelper.CreateCollectionType(arg.Type);
}
}
#endif
///
/// The aggregate type that corresponds to the invocation of an aggregate function.
///
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "Db")]
public sealed class DbFunctionAggregate : DbAggregate
{
private bool _distinct;
EdmFunction _aggregateFunction;
internal DbFunctionAggregate(DbCommandTree commandTree, EdmFunction function, DbExpression arg, bool isDistinct)
: base(commandTree)
{
EntityUtil.CheckArgumentNull(arg, "arg");
_distinct = isDistinct;
//
// Verify that the aggregate function is from the metadata collection and data space of the command tree.
//
commandTree.TypeHelper.CheckFunction(function);
// Verify that the function is actually a valid aggregate function.
// For now, only a single argument is allowed.
if (!TypeSemantics.IsAggregateFunction(function) ||
null == function.ReturnParameter ||
TypeSemantics.IsNullOrNullType(function.ReturnParameter.TypeUsage))
{
throw EntityUtil.Argument(System.Data.Entity.Strings.Cqt_Aggregate_InvalidFunction, "function");
}
_aggregateFunction = function;
// Create an ExpressionList without initializing the expected element types or element values
this.ArgumentList = new ExpressionList("Arguments", commandTree, function.Parameters.Count);
List funcArgs = CommandTreeUtils.CreateList(arg);
//
// Set the expected element type for each element in the ExpressionList based on the parameter
// type of each formal parameter to the function. For each parameter, if its parameter type is
// a collection type then the element type of that collection will be used. Otherwise the parameter
// type itself will be used. This is necessary because aggregate functions may be used outside of
// GroupBy and therefore always specify their parameter types as collection types. From within
// GroupBy the (non-collection) GroupVar may legally be passed to the same aggregate function.
// After the expected element type is set, the element value is set. This causes ExpressionLink type
// checking and other expression validation to occur against the expected element type that was just set.
//
Debug.Assert(funcArgs.Count == function.Parameters.Count, "Incorrect number of arguments specified for DbFunctionAggregate");
for (int idx = 0; idx < funcArgs.Count; idx++)
{
TypeUsage paramType = function.Parameters[idx].TypeUsage;
TypeUsage elementType = null;
if(TypeHelpers.TryGetCollectionElementType(paramType, out elementType))
{
paramType = elementType;
}
this.ArgumentList.ExpressionLinks[idx].SetExpectedType(paramType);
this.ArgumentList.ExpressionLinks[idx].InitializeValue(funcArgs[idx]);
}
this.ResultType = function.ReturnParameter.TypeUsage;
}
///
/// Gets a value indicating whether the aggregate function is applied in a distinct fashion
///
public bool Distinct { get { return _distinct; } }
///
/// Gets the method metadata that specifies the aggregate function to invoke.
///
public EdmFunction Function { get { return _aggregateFunction; } }
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SafeUserTokenHandle.cs
- CryptoProvider.cs
- XmlTextReaderImplHelpers.cs
- DataSourceXmlClassAttribute.cs
- ColorConverter.cs
- ButtonBase.cs
- DrawingVisual.cs
- RC2.cs
- XmlQueryRuntime.cs
- BrushMappingModeValidation.cs
- ColumnWidthChangedEvent.cs
- XPathEmptyIterator.cs
- webclient.cs
- PropertyHelper.cs
- StyleSelector.cs
- VerificationAttribute.cs
- SiteMapNode.cs
- ServiceDescription.cs
- ShadowGlyph.cs
- ChangeDirector.cs
- DiffuseMaterial.cs
- LocatorPartList.cs
- SafeNativeMethodsCLR.cs
- SafeUserTokenHandle.cs
- ServiceMetadataPublishingElement.cs
- MultiDataTrigger.cs
- StrokeCollection.cs
- InkPresenterAutomationPeer.cs
- FilterException.cs
- EnumerableRowCollectionExtensions.cs
- ByteStorage.cs
- FixedFlowMap.cs
- PrimarySelectionGlyph.cs
- Error.cs
- GrammarBuilderWildcard.cs
- CodeBinaryOperatorExpression.cs
- MailAddressParser.cs
- WindowsSlider.cs
- SspiNegotiationTokenAuthenticatorState.cs
- PrivateUnsafeNativeCompoundFileMethods.cs
- WrappedKeySecurityTokenParameters.cs
- CharacterBufferReference.cs
- EdmConstants.cs
- IPPacketInformation.cs
- ThrowHelper.cs
- CategoryGridEntry.cs
- DecoratedNameAttribute.cs
- _KerberosClient.cs
- RequestCache.cs
- HttpBufferlessInputStream.cs
- SpellerStatusTable.cs
- SettingsContext.cs
- MetadataResolver.cs
- XappLauncher.cs
- MouseEventArgs.cs
- FontUnitConverter.cs
- SystemUdpStatistics.cs
- HandlerFactoryWrapper.cs
- BinaryObjectInfo.cs
- PersonalizableAttribute.cs
- EventProvider.cs
- TagPrefixCollection.cs
- Underline.cs
- UrlMappingsModule.cs
- HtmlInputCheckBox.cs
- RemoteHelper.cs
- Trace.cs
- DataGridViewRowPrePaintEventArgs.cs
- HighlightComponent.cs
- UrlMapping.cs
- Translator.cs
- Overlapped.cs
- DbExpressionRules.cs
- BackgroundWorker.cs
- TraceListeners.cs
- ContentTypeSettingDispatchMessageFormatter.cs
- ParsedAttributeCollection.cs
- DataException.cs
- TypeElement.cs
- CompoundFileStreamReference.cs
- SimpleWebHandlerParser.cs
- SizeLimitedCache.cs
- FillRuleValidation.cs
- CLSCompliantAttribute.cs
- cookiecollection.cs
- HostingEnvironmentException.cs
- StrokeCollectionConverter.cs
- ValidationError.cs
- ADMembershipUser.cs
- HtmlHistory.cs
- BufferBuilder.cs
- DependencyPropertyHelper.cs
- PassportAuthenticationModule.cs
- MonthChangedEventArgs.cs
- WinEventWrap.cs
- InfoCardSymmetricAlgorithm.cs
- PerfService.cs
- InputLanguageSource.cs
- PathGeometry.cs
- ErasingStroke.cs