Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- Parser.cs
- MediaEntryAttribute.cs
- HideDisabledControlAdapter.cs
- WebUtil.cs
- TextAutomationPeer.cs
- Size.cs
- GenericPrincipal.cs
- IgnorePropertiesAttribute.cs
- ImageSource.cs
- addressfiltermode.cs
- PermissionToken.cs
- ProtocolProfile.cs
- GridViewRow.cs
- DataGridTextBoxColumn.cs
- String.cs
- SpnEndpointIdentity.cs
- XPathNodeHelper.cs
- AttributeCollection.cs
- Cloud.cs
- RelatedPropertyManager.cs
- EdmItemError.cs
- TimeZone.cs
- TypographyProperties.cs
- CollectionViewSource.cs
- WebPartVerbCollection.cs
- StylusPointCollection.cs
- WmlTextBoxAdapter.cs
- smtppermission.cs
- StorageEntityContainerMapping.cs
- Activator.cs
- _HelperAsyncResults.cs
- ResponseBodyWriter.cs
- SecurityChannelFaultConverter.cs
- TextBlockAutomationPeer.cs
- ImmComposition.cs
- _DisconnectOverlappedAsyncResult.cs
- ResourceType.cs
- CommandConverter.cs
- Perspective.cs
- objectresult_tresulttype.cs
- InstanceLockQueryResult.cs
- ConfigErrorGlyph.cs
- CreateUserWizard.cs
- ToolBarButtonClickEvent.cs
- FormViewUpdateEventArgs.cs
- CodeTypeDeclarationCollection.cs
- RedirectionProxy.cs
- RegexCompiler.cs
- ClassicBorderDecorator.cs
- ErrorLog.cs
- CacheAxisQuery.cs
- ISAPIRuntime.cs
- StreamedWorkflowDefinitionContext.cs
- TextBox.cs
- LockRecoveryTask.cs
- DescendentsWalkerBase.cs
- Binding.cs
- QueryExpr.cs
- LambdaCompiler.cs
- base64Transforms.cs
- SelectionEditingBehavior.cs
- AggregateNode.cs
- InfoCardListRequest.cs
- DesignSurfaceServiceContainer.cs
- RenameRuleObjectDialog.cs
- Vector3DCollectionConverter.cs
- HtmlTableCellCollection.cs
- RequestQueue.cs
- DataMemberFieldEditor.cs
- DocumentSchemaValidator.cs
- SqlReorderer.cs
- WorkflowMarkupSerializationException.cs
- ActivityValidator.cs
- RoutedPropertyChangedEventArgs.cs
- securestring.cs
- EventHandlerList.cs
- ObjectDataSourceDesigner.cs
- precedingquery.cs
- TemplateParser.cs
- DataRowView.cs
- DataSourceXmlClassAttribute.cs
- XmlRawWriter.cs
- DataBindEngine.cs
- VoiceInfo.cs
- HttpHeaderCollection.cs
- MetadataPropertyAttribute.cs
- LambdaCompiler.Address.cs
- DrawingGroupDrawingContext.cs
- CompoundFileStorageReference.cs
- Parameter.cs
- WebColorConverter.cs
- XmlStreamNodeWriter.cs
- Model3DGroup.cs
- HostAdapter.cs
- SerialPort.cs
- EditorPart.cs
- XmlReaderDelegator.cs
- FixedTextPointer.cs
- TemplateBamlTreeBuilder.cs
- Types.cs