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 / SqlRemoveConstantOrderBy.cs / 1 / SqlRemoveConstantOrderBy.cs
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Data; namespace System.Data.Linq.SqlClient { using System.Data.Linq; ////// SQL doesn't allow constants in ORDER BY. /// /// Worse, an integer constant greater than 0 is treated as ORDER BY ProjectionColumn[i] so the results /// can be unexpected. /// /// The LINQ semantic for OrderBy(o=>constant) is for it to have no effect on the ordering. We enforce /// that semantic here by removing all constant columns from OrderBy. /// internal class SqlRemoveConstantOrderBy { private class Visitor : SqlVisitor { internal override SqlSelect VisitSelect(SqlSelect select) { int i = 0; Listorders = select.OrderBy; while (i < orders.Count) { SqlExpression expr = orders[i].Expression; while (expr.NodeType == SqlNodeType.DiscriminatedType) { expr = ((SqlDiscriminatedType)expr).Discriminator; } switch (expr.NodeType) { case SqlNodeType.Value: case SqlNodeType.Parameter: orders.RemoveAt(i); break; default: ++i; break; } } return base.VisitSelect(select); } } /// /// Remove relative constants from OrderBy. /// internal static SqlNode Remove(SqlNode node) { return new Visitor().Visit(node); } } } // 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; using System.Linq.Expressions; using System.Data; namespace System.Data.Linq.SqlClient { using System.Data.Linq; ////// SQL doesn't allow constants in ORDER BY. /// /// Worse, an integer constant greater than 0 is treated as ORDER BY ProjectionColumn[i] so the results /// can be unexpected. /// /// The LINQ semantic for OrderBy(o=>constant) is for it to have no effect on the ordering. We enforce /// that semantic here by removing all constant columns from OrderBy. /// internal class SqlRemoveConstantOrderBy { private class Visitor : SqlVisitor { internal override SqlSelect VisitSelect(SqlSelect select) { int i = 0; Listorders = select.OrderBy; while (i < orders.Count) { SqlExpression expr = orders[i].Expression; while (expr.NodeType == SqlNodeType.DiscriminatedType) { expr = ((SqlDiscriminatedType)expr).Discriminator; } switch (expr.NodeType) { case SqlNodeType.Value: case SqlNodeType.Parameter: orders.RemoveAt(i); break; default: ++i; break; } } return base.VisitSelect(select); } } /// /// Remove relative constants from OrderBy. /// internal static SqlNode Remove(SqlNode node) { return new Visitor().Visit(node); } } } // 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
- CredentialCache.cs
- Underline.cs
- _TransmitFileOverlappedAsyncResult.cs
- OutputCacheModule.cs
- PathFigureCollection.cs
- HyperlinkAutomationPeer.cs
- CodeTypeReferenceExpression.cs
- ObjectAnimationBase.cs
- RecordManager.cs
- TreeNodeSelectionProcessor.cs
- CodeSnippetExpression.cs
- XmlIlTypeHelper.cs
- TabPanel.cs
- DbDataReader.cs
- XsdCachingReader.cs
- TraversalRequest.cs
- XsltLibrary.cs
- DataBindingHandlerAttribute.cs
- ContainerSelectorGlyph.cs
- ReplyChannelAcceptor.cs
- PauseStoryboard.cs
- ZoneIdentityPermission.cs
- Delegate.cs
- BamlTreeUpdater.cs
- InfoCard.cs
- KeyedCollection.cs
- TemplateApplicationHelper.cs
- DesignerEditorPartChrome.cs
- SqlNamer.cs
- UniformGrid.cs
- DataGridViewRowEventArgs.cs
- ContentPosition.cs
- ActivationServices.cs
- NativeCompoundFileAPIs.cs
- ObjectViewListener.cs
- SqlUtils.cs
- ResourceDescriptionAttribute.cs
- PolyBezierSegment.cs
- InlineObject.cs
- ToolStripInSituService.cs
- SmtpTransport.cs
- PointCollectionValueSerializer.cs
- ParenExpr.cs
- XpsSerializationManager.cs
- RegistrationServices.cs
- WindowsAuthenticationModule.cs
- Query.cs
- SuppressIldasmAttribute.cs
- DefaultValueTypeConverter.cs
- HtmlInputImage.cs
- DiscreteKeyFrames.cs
- SafeNativeMethods.cs
- XamlFigureLengthSerializer.cs
- BulletedList.cs
- httpserverutility.cs
- Base64Stream.cs
- SqlConnectionFactory.cs
- ProfileSettings.cs
- Compiler.cs
- BindingExpressionUncommonField.cs
- ping.cs
- DigitShape.cs
- SslStreamSecurityUpgradeProvider.cs
- RayMeshGeometry3DHitTestResult.cs
- ModelTreeEnumerator.cs
- PersistenceException.cs
- StyleTypedPropertyAttribute.cs
- InvokePatternIdentifiers.cs
- Pens.cs
- WebHttpSecurityElement.cs
- Int16Converter.cs
- ConfigurationSection.cs
- GestureRecognitionResult.cs
- unsafeIndexingFilterStream.cs
- _BufferOffsetSize.cs
- ConstructorArgumentAttribute.cs
- Message.cs
- BufferModeSettings.cs
- FacetValueContainer.cs
- TransactionChannelFaultConverter.cs
- ExpandableObjectConverter.cs
- TabControlCancelEvent.cs
- WebControlsSection.cs
- PageCatalogPart.cs
- PersistStreamTypeWrapper.cs
- DataBindingExpressionBuilder.cs
- SimpleApplicationHost.cs
- DefinitionBase.cs
- EntityParameter.cs
- TableProviderWrapper.cs
- ChannelPoolSettingsElement.cs
- Baml6Assembly.cs
- BooleanAnimationUsingKeyFrames.cs
- SplitterPanel.cs
- XmlDataSource.cs
- DataGridParentRows.cs
- ScriptModule.cs
- RtfToXamlReader.cs
- UnderstoodHeaders.cs
- WebPartConnectionsConfigureVerb.cs