Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- ParallelTimeline.cs
- EdmPropertyAttribute.cs
- Page.cs
- XmlStringTable.cs
- BindingMAnagerBase.cs
- Hashtable.cs
- JumpList.cs
- Cursor.cs
- MimeMapping.cs
- BindingEditor.xaml.cs
- IndexExpression.cs
- GenericEnumerator.cs
- ValidatorUtils.cs
- Context.cs
- HtmlControlPersistable.cs
- ProjectionPruner.cs
- ControlParser.cs
- RegexParser.cs
- RenderCapability.cs
- DataGridViewDataErrorEventArgs.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- ReadOnlyHierarchicalDataSource.cs
- TypePropertyEditor.cs
- ValidationError.cs
- RootContext.cs
- RawStylusInputReport.cs
- XmlReflectionMember.cs
- SettingsPropertyIsReadOnlyException.cs
- HtmlShim.cs
- EncryptionUtility.cs
- VariantWrapper.cs
- GacUtil.cs
- BindValidator.cs
- TableAdapterManagerNameHandler.cs
- Message.cs
- ReadOnlyCollectionBase.cs
- XamlPoint3DCollectionSerializer.cs
- NestedContainer.cs
- NativeRecognizer.cs
- AnnotationAdorner.cs
- ValuePattern.cs
- exports.cs
- FrameworkPropertyMetadata.cs
- HttpsChannelFactory.cs
- MutableAssemblyCacheEntry.cs
- parserscommon.cs
- AutomationPropertyInfo.cs
- SimpleRecyclingCache.cs
- DiagnosticTraceSource.cs
- OpenTypeLayout.cs
- Win32SafeHandles.cs
- UnaryExpressionHelper.cs
- AutomationIdentifier.cs
- DefaultBindingPropertyAttribute.cs
- RowToParametersTransformer.cs
- SudsParser.cs
- PanelDesigner.cs
- GotoExpression.cs
- ArgIterator.cs
- EngineSiteSapi.cs
- SurrogateEncoder.cs
- LabelExpression.cs
- OutputCacheSettingsSection.cs
- XPathScanner.cs
- CatalogPartChrome.cs
- HttpValueCollection.cs
- HtmlInputSubmit.cs
- SmtpTransport.cs
- SAPICategories.cs
- SchemaInfo.cs
- TabControlEvent.cs
- PointConverter.cs
- PropertyMapper.cs
- HeaderedItemsControl.cs
- Table.cs
- HtmlInputCheckBox.cs
- SqlIdentifier.cs
- ActivityDefaults.cs
- ReadOnlyMetadataCollection.cs
- WizardStepBase.cs
- FreezableDefaultValueFactory.cs
- XmlException.cs
- ElementAtQueryOperator.cs
- GridLength.cs
- DelegatingTypeDescriptionProvider.cs
- UIElementParagraph.cs
- EditorAttribute.cs
- TimelineGroup.cs
- TextEndOfParagraph.cs
- PersonalizationAdministration.cs
- FileDialog.cs
- ToolStripSplitButton.cs
- TrackingStringDictionary.cs
- DecodeHelper.cs
- HttpPostProtocolImporter.cs
- ThreadAttributes.cs
- IriParsingElement.cs
- NotificationContext.cs
- Menu.cs
- MarkupProperty.cs