Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- filewebresponse.cs
- EventsTab.cs
- ExtendedProtectionPolicyElement.cs
- CodeAttributeDeclaration.cs
- ShaderEffect.cs
- EventProviderWriter.cs
- DataGridViewColumnDesigner.cs
- SchemaCollectionPreprocessor.cs
- ProtocolsSection.cs
- HttpHeaderCollection.cs
- XmlMembersMapping.cs
- ListViewGroupConverter.cs
- ProfileSettingsCollection.cs
- TimeSpanOrInfiniteValidator.cs
- VisualCollection.cs
- AnimatedTypeHelpers.cs
- DragEvent.cs
- StateDesigner.CommentLayoutGlyph.cs
- PrincipalPermission.cs
- baseaxisquery.cs
- MessageBox.cs
- InternalConfigSettingsFactory.cs
- InkCanvasInnerCanvas.cs
- GridProviderWrapper.cs
- SchemaTableOptionalColumn.cs
- FreezableCollection.cs
- odbcmetadatafactory.cs
- FormViewDeletedEventArgs.cs
- QilGenerator.cs
- ResXDataNode.cs
- PaginationProgressEventArgs.cs
- ListViewGroupItemCollection.cs
- FacetEnabledSchemaElement.cs
- SamlConstants.cs
- SqlServer2KCompatibilityCheck.cs
- EventWaitHandle.cs
- DoubleIndependentAnimationStorage.cs
- PasswordBoxAutomationPeer.cs
- TypedDataSourceCodeGenerator.cs
- InputElement.cs
- FormViewPagerRow.cs
- EncryptedData.cs
- WebPartCloseVerb.cs
- WindowsContainer.cs
- DataGridViewCellCollection.cs
- SetIterators.cs
- DbParameterCollectionHelper.cs
- MarshalDirectiveException.cs
- DetailsViewInsertEventArgs.cs
- TcpStreams.cs
- unsafenativemethodsother.cs
- SimplePropertyEntry.cs
- CompositeFontInfo.cs
- ContentPathSegment.cs
- ExpressionBindingCollection.cs
- ParameterSubsegment.cs
- RealProxy.cs
- EventlogProvider.cs
- BackStopAuthenticationModule.cs
- NativeMethods.cs
- RoutedCommand.cs
- SmiGettersStream.cs
- GZipDecoder.cs
- AsyncStreamReader.cs
- TextCollapsingProperties.cs
- TextBounds.cs
- DataGridViewComboBoxCell.cs
- OleDragDropHandler.cs
- DefaultValidator.cs
- Point4D.cs
- AbstractExpressions.cs
- PageVisual.cs
- AppDomainFactory.cs
- DataComponentNameHandler.cs
- Light.cs
- SchemaRegistration.cs
- MdiWindowListItemConverter.cs
- XAMLParseException.cs
- ChtmlTextWriter.cs
- BitmapData.cs
- __Filters.cs
- ExpressionBuilderContext.cs
- SmtpFailedRecipientsException.cs
- CodePropertyReferenceExpression.cs
- InstanceCollisionException.cs
- FixedFindEngine.cs
- Metadata.cs
- TreeViewItemAutomationPeer.cs
- Brush.cs
- ToolStripLocationCancelEventArgs.cs
- LineMetrics.cs
- DataBindingList.cs
- RepeaterItem.cs
- DataTableTypeConverter.cs
- TextTrailingWordEllipsis.cs
- BrowserTree.cs
- ToolStripGripRenderEventArgs.cs
- _LocalDataStore.cs
- PolicyAssertionCollection.cs
- RowVisual.cs