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
- DBConnection.cs
- TextRenderingModeValidation.cs
- XmlSchemaInclude.cs
- HashCryptoHandle.cs
- XmlEncodedRawTextWriter.cs
- ThrowHelper.cs
- TextPatternIdentifiers.cs
- PerspectiveCamera.cs
- CngUIPolicy.cs
- Int32AnimationUsingKeyFrames.cs
- XmlUtf8RawTextWriter.cs
- PolicyLevel.cs
- ToolStripOverflowButton.cs
- UnderstoodHeaders.cs
- SqlStatistics.cs
- ShutDownListener.cs
- ButtonFieldBase.cs
- SplitContainer.cs
- TransportSecurityProtocol.cs
- BitmapImage.cs
- MouseGestureConverter.cs
- XmlSerializableWriter.cs
- AsynchronousChannel.cs
- OleDbCommandBuilder.cs
- OrderedDictionaryStateHelper.cs
- AuthorizationRuleCollection.cs
- ModelTreeEnumerator.cs
- DataGridPagingPage.cs
- counter.cs
- XsdDataContractExporter.cs
- BinaryParser.cs
- OverflowException.cs
- DataGridViewSortCompareEventArgs.cs
- WorkflowCreationContext.cs
- UITypeEditors.cs
- ContextMenu.cs
- TriState.cs
- ValidatorCollection.cs
- SeverityFilter.cs
- SqlDataSourceCommandEventArgs.cs
- TextBlockAutomationPeer.cs
- KeyValuePair.cs
- DependencyObjectType.cs
- Accessible.cs
- WindowsSecurityTokenAuthenticator.cs
- CommandDevice.cs
- ToolStripDropDownButton.cs
- ScopelessEnumAttribute.cs
- NameTable.cs
- CustomPopupPlacement.cs
- DataGridTable.cs
- FigureParaClient.cs
- XmlSignatureManifest.cs
- DbConnectionHelper.cs
- ActiveXContainer.cs
- XPathMultyIterator.cs
- SoapUnknownHeader.cs
- MessageContractImporter.cs
- FamilyTypeface.cs
- CustomCredentialPolicy.cs
- ConstNode.cs
- ScriptControlDescriptor.cs
- LinqDataSourceValidationException.cs
- CommandID.cs
- TraceHelpers.cs
- ReadOnlyDataSourceView.cs
- coordinator.cs
- Error.cs
- DataGridColumnsPage.cs
- InputElement.cs
- BooleanProjectedSlot.cs
- WebPartCloseVerb.cs
- WpfXamlType.cs
- ListenerServiceInstallComponent.cs
- SchemaElementLookUpTable.cs
- ComponentManagerBroker.cs
- PasswordDeriveBytes.cs
- SessionStateModule.cs
- ScrollChangedEventArgs.cs
- EventLogPermission.cs
- PropertyCondition.cs
- DesignConnection.cs
- TextUtf8RawTextWriter.cs
- _ScatterGatherBuffers.cs
- WmlTextViewAdapter.cs
- FlowStep.cs
- EventManager.cs
- SmtpReplyReader.cs
- PasswordBoxAutomationPeer.cs
- FixedDocument.cs
- FontDialog.cs
- ExceptionHandler.cs
- CheckBoxStandardAdapter.cs
- ResourceReader.cs
- LinkedResourceCollection.cs
- PropertyChangedEventArgs.cs
- ChooseAction.cs
- KnowledgeBase.cs
- AnnotationComponentManager.cs
- KeySplineConverter.cs