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
- DBPropSet.cs
- isolationinterop.cs
- PriorityRange.cs
- ArglessEventHandlerProxy.cs
- ConditionedDesigner.cs
- DataGridSortingEventArgs.cs
- XmlILIndex.cs
- autovalidator.cs
- BitmapEffectInput.cs
- ResourceCategoryAttribute.cs
- WindowsMenu.cs
- _NegotiateClient.cs
- InternalConfigHost.cs
- PieceDirectory.cs
- DesignerVerbCollection.cs
- RichTextBoxAutomationPeer.cs
- DependencyProperty.cs
- ByteStreamMessageEncodingElement.cs
- TextEffectResolver.cs
- SplineQuaternionKeyFrame.cs
- BuildProvider.cs
- DataRelationPropertyDescriptor.cs
- DBConcurrencyException.cs
- GeneralTransform.cs
- DataGridViewColumnCollection.cs
- PropertyPath.cs
- XNodeSchemaApplier.cs
- UpDownBase.cs
- BindingBase.cs
- SqlClientWrapperSmiStreamChars.cs
- XmlSchemaAnyAttribute.cs
- LayoutManager.cs
- MDIClient.cs
- ASCIIEncoding.cs
- EndpointInfo.cs
- AnnouncementSendsAsyncResult.cs
- IconConverter.cs
- OleDbErrorCollection.cs
- HostingEnvironmentException.cs
- MetafileHeader.cs
- _HeaderInfoTable.cs
- DefaultValueConverter.cs
- CatalogPartCollection.cs
- backend.cs
- MessageDecoder.cs
- ProtocolsSection.cs
- CodeTypeReferenceSerializer.cs
- PreDigestedSignedInfo.cs
- NativeMethods.cs
- ObjectAssociationEndMapping.cs
- Point.cs
- MediaContextNotificationWindow.cs
- ConfigXmlAttribute.cs
- TableProvider.cs
- BigInt.cs
- TextServicesHost.cs
- webproxy.cs
- COM2PropertyDescriptor.cs
- VSDExceptions.cs
- BooleanExpr.cs
- SqlProcedureAttribute.cs
- RemoteX509AsymmetricSecurityKey.cs
- CompilationRelaxations.cs
- ExtenderProvidedPropertyAttribute.cs
- InvalidAsynchronousStateException.cs
- Transform3D.cs
- AuthenticationService.cs
- SqlParameterizer.cs
- ObjectResult.cs
- InfoCardTrace.cs
- PerformanceCounterPermissionEntryCollection.cs
- RuntimeWrappedException.cs
- ColorMap.cs
- ObjectStateManager.cs
- EventItfInfo.cs
- QilInvoke.cs
- ThreadExceptionEvent.cs
- FontCollection.cs
- externdll.cs
- RangeValidator.cs
- GacUtil.cs
- PasswordDeriveBytes.cs
- CollectionDataContract.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- ComEventsHelper.cs
- GridViewDeleteEventArgs.cs
- JsonXmlDataContract.cs
- arabicshape.cs
- BamlRecords.cs
- UpdatePanelTriggerCollection.cs
- PopupRootAutomationPeer.cs
- GenericIdentity.cs
- ImageBrush.cs
- WindowsGraphics.cs
- ManagementEventWatcher.cs
- XhtmlBasicPageAdapter.cs
- VisualBrush.cs
- ImportCatalogPart.cs
- RtfFormatStack.cs
- Formatter.cs