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
- RepeaterItemCollection.cs
- ObjectViewQueryResultData.cs
- AstNode.cs
- EdmProviderManifest.cs
- AssemblyAttributes.cs
- LassoSelectionBehavior.cs
- PathFigureCollection.cs
- HandlerBase.cs
- ContractAdapter.cs
- Synchronization.cs
- FunctionImportElement.cs
- HTTPRemotingHandler.cs
- BehaviorEditorPart.cs
- HandlerMappingMemo.cs
- WebPartTransformerCollection.cs
- PhoneCallDesigner.cs
- CaretElement.cs
- DBCSCodePageEncoding.cs
- HtmlButton.cs
- ItemCheckedEvent.cs
- InstanceLockException.cs
- CheckBoxPopupAdapter.cs
- QualifiedCellIdBoolean.cs
- Vars.cs
- BrowserPolicyValidator.cs
- DefaultDiscoveryService.cs
- TextSelection.cs
- ClientFormsIdentity.cs
- ProgressChangedEventArgs.cs
- ResourceSet.cs
- HostedTransportConfigurationManager.cs
- MdiWindowListStrip.cs
- Send.cs
- PenThreadPool.cs
- URLAttribute.cs
- StorageTypeMapping.cs
- SpellerError.cs
- Int16AnimationBase.cs
- ToolStripGripRenderEventArgs.cs
- WpfKnownMemberInvoker.cs
- MimeParameter.cs
- ReachDocumentSequenceSerializer.cs
- ResourceSet.cs
- Font.cs
- HostedTcpTransportManager.cs
- SelectedCellsCollection.cs
- SQLStringStorage.cs
- XmlSchemaSearchPattern.cs
- RuleEngine.cs
- LinqDataSourceSelectEventArgs.cs
- XmlSchemaAnnotated.cs
- RequestContext.cs
- newinstructionaction.cs
- RewritingValidator.cs
- GridViewUpdateEventArgs.cs
- HMACSHA512.cs
- ToolStripPanelCell.cs
- DbDataReader.cs
- CreateRefExpr.cs
- Int16.cs
- PhoneCallDesigner.cs
- SqlBulkCopyColumnMappingCollection.cs
- CellTreeNode.cs
- HtmlTernaryTree.cs
- PrimitiveXmlSerializers.cs
- Vector3DKeyFrameCollection.cs
- NotConverter.cs
- IChannel.cs
- LongSumAggregationOperator.cs
- DataControlCommands.cs
- PageVisual.cs
- Util.cs
- PlanCompiler.cs
- QilGenerator.cs
- XmlSchemas.cs
- XmlUtil.cs
- MeshGeometry3D.cs
- HostingEnvironmentException.cs
- AppearanceEditorPart.cs
- AssociationEndMember.cs
- ToolStripHighContrastRenderer.cs
- DependencyPropertyKey.cs
- KeyGestureConverter.cs
- SendKeys.cs
- SQLInt16.cs
- ConfigurationManagerInternal.cs
- SymDocumentType.cs
- InternalControlCollection.cs
- Geometry.cs
- WebPartConnectVerb.cs
- WebPartConnectionsCloseVerb.cs
- WebServiceErrorEvent.cs
- ClipboardData.cs
- MetadataSerializer.cs
- BitmapEffectInput.cs
- WebPartConnectionsDisconnectVerb.cs
- DataBoundLiteralControl.cs
- CoTaskMemUnicodeSafeHandle.cs
- SqlTriggerAttribute.cs
- ReferencedCollectionType.cs