Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DLinq / Dlinq / SqlClient / Query / SqlRewriteScalarSubqueries.cs / 1305376 / 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
- SwitchAttribute.cs
- ClassDataContract.cs
- AutoResizedEvent.cs
- TrustSection.cs
- ObjectFullSpanRewriter.cs
- HtmlTitle.cs
- WebZone.cs
- HttpInputStream.cs
- XPathItem.cs
- OutputCacheProfile.cs
- ReferenceConverter.cs
- SchemaConstraints.cs
- PageAsyncTaskManager.cs
- OrderingInfo.cs
- PropertyInformation.cs
- UrlPropertyAttribute.cs
- ClientCredentialsSecurityTokenManager.cs
- TableSectionStyle.cs
- View.cs
- DataMemberConverter.cs
- ClientWindowsAuthenticationMembershipProvider.cs
- SqlGatherConsumedAliases.cs
- XamlWriter.cs
- SecurityResources.cs
- Method.cs
- AssemblyAttributes.cs
- DeploymentExceptionMapper.cs
- ImageSourceConverter.cs
- ResourceContainer.cs
- StrokeCollectionDefaultValueFactory.cs
- FilteredAttributeCollection.cs
- WebPartActionVerb.cs
- XmlUnspecifiedAttribute.cs
- WorkflowInstance.cs
- References.cs
- CacheModeConverter.cs
- UnsafeNativeMethods.cs
- TextParentUndoUnit.cs
- SmiEventSink_Default.cs
- LogAppendAsyncResult.cs
- GroupQuery.cs
- SmiMetaDataProperty.cs
- ArrayTypeMismatchException.cs
- FocusManager.cs
- MimeBasePart.cs
- DrawTreeNodeEventArgs.cs
- DebugHandleTracker.cs
- DataSetMappper.cs
- SQLDateTime.cs
- TcpActivation.cs
- HwndSourceKeyboardInputSite.cs
- CheckBoxList.cs
- Visual.cs
- DataListComponentEditor.cs
- AssociationSetMetadata.cs
- WinEventTracker.cs
- XmlComment.cs
- WebScriptServiceHostFactory.cs
- GridItemPatternIdentifiers.cs
- AttributeProviderAttribute.cs
- DbConnectionFactory.cs
- shaperfactoryquerycacheentry.cs
- ParameterSubsegment.cs
- XmlSchemaSubstitutionGroup.cs
- Scene3D.cs
- ExpanderAutomationPeer.cs
- RawStylusActions.cs
- TextEndOfSegment.cs
- CurrentTimeZone.cs
- DeclaredTypeElementCollection.cs
- EventMappingSettings.cs
- RadialGradientBrush.cs
- CanExecuteRoutedEventArgs.cs
- DbDataAdapter.cs
- GraphicsState.cs
- XmlQueryType.cs
- DataViewListener.cs
- AsyncStreamReader.cs
- SourceElementsCollection.cs
- SqlPersonalizationProvider.cs
- WebBrowserNavigatedEventHandler.cs
- MemberRelationshipService.cs
- DecoratedNameAttribute.cs
- CodeSnippetExpression.cs
- MessageEncoderFactory.cs
- AutomationPropertyInfo.cs
- HiddenField.cs
- DaylightTime.cs
- PatternMatcher.cs
- StickyNote.cs
- State.cs
- TemplateLookupAction.cs
- SchemaObjectWriter.cs
- SimpleType.cs
- SQLGuidStorage.cs
- PrintController.cs
- PropertyChangedEventArgs.cs
- ToolStripDesignerAvailabilityAttribute.cs
- Activity.cs
- MenuItemBindingCollection.cs