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
- DESCryptoServiceProvider.cs
- FixedDocument.cs
- DLinqAssociationProvider.cs
- SaveFileDialog.cs
- StylusTip.cs
- PropertyTabAttribute.cs
- FormView.cs
- XmlSchemas.cs
- TraceListeners.cs
- OperationCanceledException.cs
- Utils.cs
- DataSpaceManager.cs
- ProcessInfo.cs
- HttpPostClientProtocol.cs
- ProvidersHelper.cs
- RepeaterItem.cs
- ContainerParagraph.cs
- ResourceCategoryAttribute.cs
- ValueSerializerAttribute.cs
- QilList.cs
- TypeSemantics.cs
- AuthorizationSection.cs
- FontFamily.cs
- HttpRawResponse.cs
- Light.cs
- CodeActivityMetadata.cs
- HttpUnhandledOperationInvoker.cs
- DataServiceRequestException.cs
- keycontainerpermission.cs
- MediaSystem.cs
- ContextMenuStripGroupCollection.cs
- TagNameToTypeMapper.cs
- SqlVersion.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- AddInController.cs
- UriTemplateVariablePathSegment.cs
- HandoffBehavior.cs
- EntitySetDataBindingList.cs
- HttpServerUtilityWrapper.cs
- HashMembershipCondition.cs
- XmlCharType.cs
- AccessibleObject.cs
- LicenseManager.cs
- ExternalDataExchangeService.cs
- ButtonDesigner.cs
- ReadOnlyMetadataCollection.cs
- RowBinding.cs
- MessagingActivityHelper.cs
- CancelEventArgs.cs
- TableLayout.cs
- EditorZone.cs
- SynchronizationLockException.cs
- PackUriHelper.cs
- WindowsFont.cs
- ExternalException.cs
- HwndMouseInputProvider.cs
- HiddenField.cs
- Int32AnimationBase.cs
- DbFunctionCommandTree.cs
- WebAdminConfigurationHelper.cs
- AmbientValueAttribute.cs
- DbExpressionBuilder.cs
- ContextMenuStrip.cs
- DataGridColumn.cs
- Stylus.cs
- ComponentConverter.cs
- VarRemapper.cs
- FileUpload.cs
- CompositeActivityMarkupSerializer.cs
- PageBuildProvider.cs
- ObjectListCommandCollection.cs
- ClockController.cs
- PropagatorResult.cs
- ProfileSettings.cs
- ProfileParameter.cs
- ToolStripControlHost.cs
- SerializationSectionGroup.cs
- SelectionRange.cs
- XPathSelfQuery.cs
- ExpandableObjectConverter.cs
- SignedXmlDebugLog.cs
- TrayIconDesigner.cs
- CustomErrorsSection.cs
- MimeMapping.cs
- DataGridViewButtonCell.cs
- ServiceMetadataContractBehavior.cs
- AssertSection.cs
- ApplyImportsAction.cs
- XamlToRtfWriter.cs
- GridItemProviderWrapper.cs
- EventDescriptor.cs
- Visual.cs
- DeleteIndexBinder.cs
- LeaseManager.cs
- HtmlElementEventArgs.cs
- OdbcReferenceCollection.cs
- PersistChildrenAttribute.cs
- DoubleCollection.cs
- BrowserDefinition.cs
- LinqDataSourceValidationException.cs