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
- PersonalizationProvider.cs
- ExtendedPropertyDescriptor.cs
- ResourceReferenceExpression.cs
- BaseParaClient.cs
- PopupControlService.cs
- PipelineComponent.cs
- Int32Rect.cs
- DataGridViewCellEventArgs.cs
- RootBrowserWindow.cs
- MissingMemberException.cs
- PointCollectionValueSerializer.cs
- CommentAction.cs
- RowType.cs
- UserNamePasswordValidator.cs
- SafeNativeMemoryHandle.cs
- ClientBuildManagerCallback.cs
- Popup.cs
- IconBitmapDecoder.cs
- PassportAuthenticationEventArgs.cs
- XmlAnyElementAttribute.cs
- BitConverter.cs
- CodeTypeMemberCollection.cs
- dataprotectionpermission.cs
- WebPartExportVerb.cs
- PasswordPropertyTextAttribute.cs
- EntitySetRetriever.cs
- TypePropertyEditor.cs
- ADMembershipUser.cs
- CreateInstanceBinder.cs
- ProgressBarRenderer.cs
- ExecutedRoutedEventArgs.cs
- HtmlTernaryTree.cs
- TextContainerHelper.cs
- ZipIOLocalFileHeader.cs
- entityreference_tresulttype.cs
- ToolboxItemFilterAttribute.cs
- TemplateField.cs
- UpdatePanel.cs
- ThreadPoolTaskScheduler.cs
- AttributeAction.cs
- TPLETWProvider.cs
- AudioFileOut.cs
- CodeDefaultValueExpression.cs
- ToolStripItemDataObject.cs
- DocumentReference.cs
- EntryIndex.cs
- VersionPair.cs
- ReadOnlyCollection.cs
- OdbcConnectionStringbuilder.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- StylusButtonEventArgs.cs
- SessionPageStateSection.cs
- QuestionEventArgs.cs
- SqlError.cs
- SrgsElement.cs
- BitmapEffectInputData.cs
- ValuePattern.cs
- EndpointDiscoveryMetadata11.cs
- MessageDesigner.cs
- EmptyElement.cs
- ExceptionUtility.cs
- BitmapEffectInputConnector.cs
- PageRequestManager.cs
- PermissionRequestEvidence.cs
- ProtocolsSection.cs
- NavigationWindowAutomationPeer.cs
- MdiWindowListStrip.cs
- ProcessHostFactoryHelper.cs
- MenuAutomationPeer.cs
- StaticExtension.cs
- BooleanToVisibilityConverter.cs
- DrawToolTipEventArgs.cs
- ListGeneralPage.cs
- TemplatedEditableDesignerRegion.cs
- Matrix.cs
- EntityDataSourceSelectingEventArgs.cs
- NativeMethods.cs
- MachineKey.cs
- HttpCacheParams.cs
- ProcessModule.cs
- KeyGestureValueSerializer.cs
- VectorAnimationUsingKeyFrames.cs
- CoordinationService.cs
- KeyPressEvent.cs
- ToolStripStatusLabel.cs
- MaskDescriptor.cs
- MenuItemBindingCollection.cs
- DisplayNameAttribute.cs
- DeviceContext2.cs
- XmlDocument.cs
- WsdlImporterElement.cs
- WebPartTransformerAttribute.cs
- DiffuseMaterial.cs
- IsolatedStorageFileStream.cs
- ConfigurationSectionCollection.cs
- DiagnosticsConfiguration.cs
- DecimalFormatter.cs
- PreservationFileReader.cs
- SafeRegistryHandle.cs
- updatecommandorderer.cs