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
- HWStack.cs
- BinaryObjectInfo.cs
- OleDbError.cs
- WebSysDescriptionAttribute.cs
- UIHelper.cs
- WrappedIUnknown.cs
- SqlUserDefinedAggregateAttribute.cs
- ConnectionStringsExpressionBuilder.cs
- FormsAuthenticationCredentials.cs
- ObjectListCommand.cs
- ControlAdapter.cs
- FacetChecker.cs
- TableItemPatternIdentifiers.cs
- ToolStripTextBox.cs
- ParameterBuilder.cs
- LinkedList.cs
- ScriptResourceInfo.cs
- FixedSOMTable.cs
- XmlILIndex.cs
- Event.cs
- HashSet.cs
- OracleSqlParser.cs
- AppDomainProtocolHandler.cs
- ContentFilePart.cs
- DesignerActionService.cs
- Types.cs
- DispatcherSynchronizationContext.cs
- PointHitTestResult.cs
- HttpWriter.cs
- RemoteWebConfigurationHostStream.cs
- SqlDataSourceTableQuery.cs
- RTLAwareMessageBox.cs
- ReadOnlyCollection.cs
- TouchesOverProperty.cs
- CustomErrorsSection.cs
- GridItemCollection.cs
- diagnosticsswitches.cs
- DataServiceSaveChangesEventArgs.cs
- ProcessHost.cs
- DynamicContractTypeBuilder.cs
- WindowsPrincipal.cs
- Parser.cs
- SetterBase.cs
- TabRenderer.cs
- ThicknessAnimation.cs
- QueryCacheKey.cs
- ProcessInfo.cs
- DataObjectMethodAttribute.cs
- UrlParameterWriter.cs
- LoginView.cs
- WebPartTransformer.cs
- Matrix.cs
- __FastResourceComparer.cs
- CatalogPartChrome.cs
- ConfigurationElementProperty.cs
- QueryAccessibilityHelpEvent.cs
- AnnotationMap.cs
- IndependentAnimationStorage.cs
- StateMachineWorkflowDesigner.cs
- EventEntry.cs
- SoapObjectInfo.cs
- FileSystemEventArgs.cs
- DataGridLinkButton.cs
- Vector3D.cs
- RelationshipEnd.cs
- XPathNodeList.cs
- UserMapPath.cs
- AppliedDeviceFiltersDialog.cs
- AttributeSetAction.cs
- AccessorTable.cs
- NavigationProperty.cs
- ContentFilePart.cs
- CodeGenerator.cs
- MemberDescriptor.cs
- ThemeDirectoryCompiler.cs
- IProvider.cs
- PathFigure.cs
- DashStyle.cs
- VisualTreeUtils.cs
- Assembly.cs
- MediaElementAutomationPeer.cs
- MethodCallConverter.cs
- ListParagraph.cs
- BaseDataList.cs
- DecimalConstantAttribute.cs
- AuthenticationService.cs
- TemplateKey.cs
- COMException.cs
- ObservableCollection.cs
- ToolStripSplitButton.cs
- Quaternion.cs
- Component.cs
- ArraySegment.cs
- RouteCollection.cs
- ContractUtils.cs
- MgmtConfigurationRecord.cs
- XmlWrappingReader.cs
- HashJoinQueryOperatorEnumerator.cs
- MouseGesture.cs
- mongolianshape.cs