Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DLinq / Dlinq / SqlClient / Query / SqlRemoveConstantOrderBy.cs / 1305376 / 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
- SecurityPermission.cs
- FontEmbeddingManager.cs
- ContainerControl.cs
- Slider.cs
- BindingOperations.cs
- ExceptionUtility.cs
- EntityDataSource.cs
- LedgerEntryCollection.cs
- StreamUpgradeAcceptor.cs
- StrokeNodeOperations2.cs
- TypeValidationEventArgs.cs
- COM2IDispatchConverter.cs
- FixedSOMTextRun.cs
- DecodeHelper.cs
- URLString.cs
- TextEndOfLine.cs
- ConnectionConsumerAttribute.cs
- XmlEntityReference.cs
- UnsafeNativeMethodsCLR.cs
- FunctionQuery.cs
- ModifierKeysValueSerializer.cs
- PublisherMembershipCondition.cs
- DataGridViewRowPrePaintEventArgs.cs
- TriggerBase.cs
- SslStreamSecurityBindingElement.cs
- MLangCodePageEncoding.cs
- PeerNameResolver.cs
- XmlSerializationGeneratedCode.cs
- OleAutBinder.cs
- TextBoxLine.cs
- initElementDictionary.cs
- XpsS0ValidatingLoader.cs
- Command.cs
- GeneralTransformCollection.cs
- WebInvokeAttribute.cs
- PathSegment.cs
- path.cs
- ConfigXmlReader.cs
- counter.cs
- XamlClipboardData.cs
- MemoryMappedFile.cs
- SignedXmlDebugLog.cs
- ProxyGenerationError.cs
- TransportContext.cs
- DispatcherEventArgs.cs
- HttpListener.cs
- SymmetricKeyWrap.cs
- ListSortDescription.cs
- TemplateBindingExpressionConverter.cs
- SystemWebSectionGroup.cs
- EFTableProvider.cs
- WebBrowsableAttribute.cs
- Overlapped.cs
- ToolStripDesigner.cs
- Completion.cs
- AsyncSerializedWorker.cs
- StrongNameKeyPair.cs
- WinEventHandler.cs
- DrawingCollection.cs
- PagedDataSource.cs
- DeviceContext.cs
- ImageDrawing.cs
- Pkcs9Attribute.cs
- ColorTransformHelper.cs
- DefaultPrintController.cs
- DataView.cs
- CatalogZone.cs
- PersonalizationStateInfo.cs
- RegexMatch.cs
- UnconditionalPolicy.cs
- TextEditorParagraphs.cs
- SoapDocumentServiceAttribute.cs
- SchemaNotation.cs
- FontDriver.cs
- Material.cs
- InkCanvasSelection.cs
- QueueException.cs
- EdmFunction.cs
- LogEntryHeaderDeserializer.cs
- EventsTab.cs
- SqlDataSourceConfigureSortForm.cs
- DtrList.cs
- MediaTimeline.cs
- Blend.cs
- TraceLevelStore.cs
- CheckBoxAutomationPeer.cs
- FillRuleValidation.cs
- FragmentQuery.cs
- AudioStateChangedEventArgs.cs
- ColorPalette.cs
- OperatingSystem.cs
- CommandHelper.cs
- ToolStripDesignerAvailabilityAttribute.cs
- Knowncolors.cs
- NavigationWindow.cs
- PointAnimation.cs
- XmlJsonReader.cs
- StreamGeometry.cs
- LZCodec.cs
- ChannelServices.cs