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
- ProtocolsConfigurationEntry.cs
- SoapAttributeOverrides.cs
- WinFormsUtils.cs
- SafeWaitHandle.cs
- ConnectAlgorithms.cs
- ComponentEditorPage.cs
- Label.cs
- MeshGeometry3D.cs
- DataMemberConverter.cs
- PageBuildProvider.cs
- ArraySet.cs
- HtmlControlPersistable.cs
- ProfileManager.cs
- UniqueIdentifierService.cs
- XmlTextEncoder.cs
- CurrentChangingEventManager.cs
- KerberosRequestorSecurityToken.cs
- EntityDataSourceChangingEventArgs.cs
- EntityDataSourceQueryBuilder.cs
- SqlDependencyUtils.cs
- Grant.cs
- HtmlCalendarAdapter.cs
- UIElement.cs
- Cursors.cs
- FixedStringLookup.cs
- DotExpr.cs
- WindowsNonControl.cs
- ApplicationDirectory.cs
- Hashtable.cs
- ProfileBuildProvider.cs
- MenuItemStyleCollection.cs
- CommonServiceBehaviorElement.cs
- FromRequest.cs
- CharUnicodeInfo.cs
- IApplicationTrustManager.cs
- WmfPlaceableFileHeader.cs
- TraceHwndHost.cs
- ImageAttributes.cs
- MDIControlStrip.cs
- LogConverter.cs
- DataMisalignedException.cs
- RowVisual.cs
- EncryptedReference.cs
- SignedInfo.cs
- FacetDescription.cs
- ListBoxItemAutomationPeer.cs
- DateTimeSerializationSection.cs
- CookielessHelper.cs
- LinqDataSourceEditData.cs
- ScrollBarRenderer.cs
- Section.cs
- httpserverutility.cs
- SecurityChannelListener.cs
- ErrorRuntimeConfig.cs
- CodeTypeDeclaration.cs
- DateBoldEvent.cs
- ConfigurationSectionGroup.cs
- SQLBinary.cs
- AndCondition.cs
- Floater.cs
- CancellableEnumerable.cs
- PolyLineSegment.cs
- ObjectToIdCache.cs
- FrameworkReadOnlyPropertyMetadata.cs
- AdornerLayer.cs
- DropDownList.cs
- DbTransaction.cs
- SafePointer.cs
- SoapAttributes.cs
- ClientTargetSection.cs
- WaitForChangedResult.cs
- WebControl.cs
- Table.cs
- XmlILConstructAnalyzer.cs
- EnumValAlphaComparer.cs
- WebPartMovingEventArgs.cs
- VectorCollectionConverter.cs
- DataTableNewRowEvent.cs
- MessageSmuggler.cs
- SqlUdtInfo.cs
- DataServiceKeyAttribute.cs
- ToolStripOverflow.cs
- PermissionRequestEvidence.cs
- OracleEncoding.cs
- Menu.cs
- RoleService.cs
- SecurityUniqueId.cs
- QuaternionAnimation.cs
- ScrollBarRenderer.cs
- SplashScreenNativeMethods.cs
- ArrayWithOffset.cs
- QualifiedCellIdBoolean.cs
- DBConnection.cs
- Validator.cs
- ScriptingJsonSerializationSection.cs
- DefaultSection.cs
- OraclePermission.cs
- StringValueSerializer.cs
- TableCellCollection.cs
- SqlComparer.cs