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
- ArrangedElement.cs
- InputReferenceExpression.cs
- OrderedDictionary.cs
- DeadCharTextComposition.cs
- CssStyleCollection.cs
- WebPartTransformerAttribute.cs
- WpfMemberInvoker.cs
- BitmapData.cs
- ControlTemplate.cs
- WebPartUserCapability.cs
- GPRECTF.cs
- GacUtil.cs
- ConfigurationValidatorAttribute.cs
- RectAnimationBase.cs
- ColorConverter.cs
- CachedResourceDictionaryExtension.cs
- selecteditemcollection.cs
- ChannelServices.cs
- CacheSection.cs
- Publisher.cs
- EntityTypeEmitter.cs
- UpDownEvent.cs
- WindowsTab.cs
- TailCallAnalyzer.cs
- XamlFilter.cs
- UIElement3D.cs
- ProxyGenerator.cs
- DbgUtil.cs
- CompilerResults.cs
- NotCondition.cs
- WinHttpWebProxyFinder.cs
- BaseComponentEditor.cs
- RegexCompilationInfo.cs
- PaperSize.cs
- ButtonAutomationPeer.cs
- IOException.cs
- AssemblyResourceLoader.cs
- MDIWindowDialog.cs
- DataRecord.cs
- _NativeSSPI.cs
- OutOfMemoryException.cs
- CqlLexerHelpers.cs
- UnsafeNativeMethods.cs
- DeferredReference.cs
- FtpCachePolicyElement.cs
- AxDesigner.cs
- RoleBoolean.cs
- XmlSchemaSimpleTypeUnion.cs
- X509CertificateTrustedIssuerElementCollection.cs
- ClipboardProcessor.cs
- ByteStreamMessageEncoderFactory.cs
- DataGridComboBoxColumn.cs
- MissingSatelliteAssemblyException.cs
- ForEachAction.cs
- PathTooLongException.cs
- ResourceProviderFactory.cs
- ConfigXmlAttribute.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- SqlDesignerDataSourceView.cs
- MailHeaderInfo.cs
- SuppressIldasmAttribute.cs
- TextTabProperties.cs
- Repeater.cs
- SQLRoleProvider.cs
- CompilerHelpers.cs
- ReplacementText.cs
- LinqDataSourceDisposeEventArgs.cs
- AsyncCompletedEventArgs.cs
- CompleteWizardStep.cs
- SHA256.cs
- InvokeBase.cs
- JapaneseLunisolarCalendar.cs
- TabControlAutomationPeer.cs
- AdapterSwitches.cs
- WebPartCatalogAddVerb.cs
- HtmlHistory.cs
- CollectionDataContract.cs
- SqlDelegatedTransaction.cs
- CompressStream.cs
- ColorMap.cs
- TimeSpanStorage.cs
- FocusChangedEventArgs.cs
- HashAlgorithm.cs
- ValidationService.cs
- RawStylusActions.cs
- LogicalTreeHelper.cs
- EmptyControlCollection.cs
- QilUnary.cs
- TextTreeFixupNode.cs
- DrawingVisual.cs
- XmlParserContext.cs
- AutomationIdentifierGuids.cs
- UseManagedPresentationBindingElementImporter.cs
- SerialPinChanges.cs
- ItemCheckEvent.cs
- Stack.cs
- MappingItemCollection.cs
- SecurityDocument.cs
- BitmapVisualManager.cs
- InternalControlCollection.cs