Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DLinq / Dlinq / SqlClient / Query / SqlRewriteScalarSubqueries.cs / 1 / SqlRewriteScalarSubqueries.cs
using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Data.Linq; namespace System.Data.Linq.SqlClient { // converts correlated scalar subqueries into outer-applies // must be run after flattener. internal class SqlRewriteScalarSubqueries { Visitor visitor; internal SqlRewriteScalarSubqueries(SqlFactory sqlFactory) { this.visitor = new Visitor(sqlFactory); } internal SqlNode Rewrite(SqlNode node) { return this.visitor.Visit(node); } class Visitor : SqlVisitor { SqlFactory sql; SqlSelect currentSelect; SqlAggregateChecker aggregateChecker; internal Visitor(SqlFactory sqlFactory) { this.sql = sqlFactory; this.aggregateChecker = new SqlAggregateChecker(); } internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss) { SqlSelect innerSelect = this.VisitSelect(ss.Select); if (!this.aggregateChecker.HasAggregates(innerSelect)) { innerSelect.Top = this.sql.ValueFromObject(1, ss.SourceExpression); } innerSelect.OrderingType = SqlOrderingType.Blocked; SqlAlias alias = new SqlAlias(innerSelect); this.currentSelect.From = new SqlJoin(SqlJoinType.OuterApply, this.currentSelect.From, alias, null, ss.SourceExpression); return new SqlColumnRef(innerSelect.Row.Columns[0]); } internal override SqlSelect VisitSelect(SqlSelect select) { SqlSelect save = this.currentSelect; try { this.currentSelect = select; return base.VisitSelect(select); } finally { this.currentSelect = save; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Data.Linq; namespace System.Data.Linq.SqlClient { // converts correlated scalar subqueries into outer-applies // must be run after flattener. internal class SqlRewriteScalarSubqueries { Visitor visitor; internal SqlRewriteScalarSubqueries(SqlFactory sqlFactory) { this.visitor = new Visitor(sqlFactory); } internal SqlNode Rewrite(SqlNode node) { return this.visitor.Visit(node); } class Visitor : SqlVisitor { SqlFactory sql; SqlSelect currentSelect; SqlAggregateChecker aggregateChecker; internal Visitor(SqlFactory sqlFactory) { this.sql = sqlFactory; this.aggregateChecker = new SqlAggregateChecker(); } internal override SqlExpression VisitScalarSubSelect(SqlSubSelect ss) { SqlSelect innerSelect = this.VisitSelect(ss.Select); if (!this.aggregateChecker.HasAggregates(innerSelect)) { innerSelect.Top = this.sql.ValueFromObject(1, ss.SourceExpression); } innerSelect.OrderingType = SqlOrderingType.Blocked; SqlAlias alias = new SqlAlias(innerSelect); this.currentSelect.From = new SqlJoin(SqlJoinType.OuterApply, this.currentSelect.From, alias, null, ss.SourceExpression); return new SqlColumnRef(innerSelect.Row.Columns[0]); } internal override SqlSelect VisitSelect(SqlSelect select) { SqlSelect save = this.currentSelect; try { this.currentSelect = select; return base.VisitSelect(select); } finally { this.currentSelect = save; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FontResourceCache.cs
- InvalidFilterCriteriaException.cs
- CallbackHandler.cs
- ExplicitDiscriminatorMap.cs
- filewebresponse.cs
- SchemaImporterExtension.cs
- ETagAttribute.cs
- CommonObjectSecurity.cs
- ToolBarButtonClickEvent.cs
- PersonalizationStateQuery.cs
- HitTestDrawingContextWalker.cs
- ServiceModelSecurityTokenRequirement.cs
- XmlDataSourceNodeDescriptor.cs
- SoapFormatter.cs
- Int32.cs
- EditingCommands.cs
- DeferredRunTextReference.cs
- PermissionAttributes.cs
- TCEAdapterGenerator.cs
- TraceEventCache.cs
- SqlHelper.cs
- LogicalChannel.cs
- XmlSchemaCollection.cs
- ClassData.cs
- HelpEvent.cs
- ToolTipService.cs
- ActivationService.cs
- XpsDigitalSignature.cs
- DesignerDeviceConfig.cs
- ParseNumbers.cs
- Hash.cs
- EasingKeyFrames.cs
- SqlColumnizer.cs
- Cursor.cs
- EntityContainer.cs
- WebPartCollection.cs
- OlePropertyStructs.cs
- QueryStringParameter.cs
- LazyTextWriterCreator.cs
- ProtocolReflector.cs
- RightsManagementEncryptedStream.cs
- EnumBuilder.cs
- CacheAxisQuery.cs
- MissingMethodException.cs
- SerialStream.cs
- XpsS0ValidatingLoader.cs
- TimeSpan.cs
- EdmComplexPropertyAttribute.cs
- returneventsaver.cs
- NamespaceEmitter.cs
- SerTrace.cs
- UserPreferenceChangedEventArgs.cs
- GeometryValueSerializer.cs
- ConnectionStringsSection.cs
- DataBindingHandlerAttribute.cs
- VirtualDirectoryMappingCollection.cs
- XhtmlBasicLabelAdapter.cs
- IPPacketInformation.cs
- DurableInstance.cs
- UshortList2.cs
- DbConnectionInternal.cs
- Int32.cs
- DesignerTransactionCloseEvent.cs
- COM2FontConverter.cs
- StreamMarshaler.cs
- TemplateKey.cs
- Collection.cs
- MappingException.cs
- SdlChannelSink.cs
- SignatureHelper.cs
- DataSourceCacheDurationConverter.cs
- TransportationConfigurationTypeInstallComponent.cs
- IsolatedStorageException.cs
- RemotingConfiguration.cs
- WebConfigurationHostFileChange.cs
- ConnectionsZone.cs
- ApplicationDirectoryMembershipCondition.cs
- COSERVERINFO.cs
- OutputScope.cs
- TrackingValidationObjectDictionary.cs
- ISessionStateStore.cs
- StreamInfo.cs
- FillErrorEventArgs.cs
- SmiContext.cs
- GraphicsContainer.cs
- Internal.cs
- URL.cs
- ParseNumbers.cs
- SqlIdentifier.cs
- CriticalHandle.cs
- ListView.cs
- ListBoxAutomationPeer.cs
- EmptyImpersonationContext.cs
- HwndKeyboardInputProvider.cs
- NotifyCollectionChangedEventArgs.cs
- ArrayConverter.cs
- WebBaseEventKeyComparer.cs
- WebPartZoneBase.cs
- File.cs
- DataList.cs