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
- ObjectQueryProvider.cs
- ColorMatrix.cs
- JsonEnumDataContract.cs
- DataTablePropertyDescriptor.cs
- WSDualHttpBindingCollectionElement.cs
- SHA384Cng.cs
- CopyNamespacesAction.cs
- UserValidatedEventArgs.cs
- PagesSection.cs
- InvokeWebService.cs
- RunWorkerCompletedEventArgs.cs
- FactoryId.cs
- BinaryObjectReader.cs
- PeerCollaborationPermission.cs
- TypeDescriptionProviderAttribute.cs
- COM2EnumConverter.cs
- DPTypeDescriptorContext.cs
- ConnectionStringSettings.cs
- _SSPIWrapper.cs
- MenuAdapter.cs
- InvokeHandlers.cs
- FormViewRow.cs
- SoapTypeAttribute.cs
- GlyphCollection.cs
- InnerItemCollectionView.cs
- ColorContext.cs
- SystemTcpStatistics.cs
- WebHeaderCollection.cs
- RelatedPropertyManager.cs
- CompilationAssemblyInstallComponent.cs
- MetadataWorkspace.cs
- DispatcherFrame.cs
- safesecurityhelperavalon.cs
- CookieProtection.cs
- MethodCallTranslator.cs
- ExceptionUtility.cs
- VoiceChangeEventArgs.cs
- EventDescriptor.cs
- SnapshotChangeTrackingStrategy.cs
- AnnotationComponentManager.cs
- ConstructorNeedsTagAttribute.cs
- ValidatorCollection.cs
- DataMember.cs
- RadioButtonPopupAdapter.cs
- AsyncResult.cs
- XmlExpressionDumper.cs
- WindowInteropHelper.cs
- ServicesSection.cs
- Transform.cs
- BamlRecordWriter.cs
- SecurityResources.cs
- PermissionSetEnumerator.cs
- TransformGroup.cs
- BitmapFrameEncode.cs
- _TimerThread.cs
- BindingsCollection.cs
- AbstractExpressions.cs
- XmlDeclaration.cs
- CellParagraph.cs
- PasswordBox.cs
- WpfPayload.cs
- KeyedByTypeCollection.cs
- DNS.cs
- SmiEventSink_DeferedProcessing.cs
- GeneralTransform3DTo2D.cs
- StringToken.cs
- ParameterCollection.cs
- RegistryDataKey.cs
- EventBuilder.cs
- FactoryMaker.cs
- TreeChangeInfo.cs
- AuthenticatedStream.cs
- XmlSchemaChoice.cs
- HttpConfigurationSystem.cs
- PrintDialog.cs
- DataServiceHostFactory.cs
- CapabilitiesAssignment.cs
- AuditLevel.cs
- MediaContextNotificationWindow.cs
- XmlToDatasetMap.cs
- objectquery_tresulttype.cs
- TimeSpan.cs
- DefaultBinder.cs
- ImageListStreamer.cs
- DPCustomTypeDescriptor.cs
- RSAOAEPKeyExchangeFormatter.cs
- Compiler.cs
- ScriptIgnoreAttribute.cs
- EndpointAddressAugust2004.cs
- FormViewPagerRow.cs
- DataColumnPropertyDescriptor.cs
- EncodingNLS.cs
- SQLInt32.cs
- HighlightVisual.cs
- PlatformNotSupportedException.cs
- smtppermission.cs
- SignatureTargetIdManager.cs
- SerialPort.cs
- DataGridState.cs
- DetailsViewUpdateEventArgs.cs