Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / ELinq / BindingContext.cs / 1305376 / BindingContext.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] //--------------------------------------------------------------------- using CqtExpression = System.Data.Common.CommandTrees.DbExpression; using LinqExpression = System.Linq.Expressions.Expression; using System.Linq.Expressions; using System.Collections.ObjectModel; using System.Linq; using System.Collections.Generic; using System.Data.Common.CommandTrees; using System.Data.Metadata.Edm; using System.Reflection; using System.Data.Common.EntitySql; using System.Diagnostics; using System.Data.Common; using System.Globalization; namespace System.Data.Objects.ELinq { ////// Class containing binding information for an expression converter (associating CQT bindings /// with LINQ lambda parameter or LINQ sub-expressions) /// ////// Usage pattern: /// internal sealed class BindingContext { private readonly Stack/// BindingContext context = ...; /// /// // translate a "Where" lamba expression input.Where(i => i.X > 2); /// LambdaExpression whereLambda = ...; /// CqtExpression inputCqt = Translate(whereLambda.Arguments[1]); /// CqtExpression inputBinding = CreateExpressionBinding(inputCqt).Var; /// /// // push the scope defined by the parameter /// context.PushBindingScope(new KeyValuePair{ParameterExpression, CqtExpression}(whereLambda.Parameters[0], inputBinding)); /// /// // translate the expression in this context /// CqtExpression result = Translate(whereLambda.Expression); /// /// // pop the scope /// context.PopBindingScope(); ///
///_scopes; /// /// Initialize a new binding context /// internal BindingContext() { _scopes = new Stack(); } /// /// Set up a new binding scope where parameter expressions map to their paired CQT expressions. /// /// DbExpression/LinqExpression binding internal void PushBindingScope(Binding binding) { _scopes.Push(binding); } ////// Removes a scope when leaving a particular sub-expression. /// ///Scope. internal void PopBindingScope() { _scopes.Pop(); } internal bool TryGetBoundExpression(Expression linqExpression, out CqtExpression cqtExpression) { cqtExpression = _scopes .Where(binding => binding.LinqExpression == linqExpression) .Select(binding => binding.CqtExpression) .FirstOrDefault(); return cqtExpression != null; } } ////// Class describing a LINQ parameter and its bound expression. For instance, in /// /// products.Select(p => p.ID) /// /// the 'products' query is the bound expression, and 'p' is the parameter. /// internal sealed class Binding { internal Binding(Expression linqExpression, CqtExpression cqtExpression) { EntityUtil.CheckArgumentNull(linqExpression, "linqExpression"); EntityUtil.CheckArgumentNull(cqtExpression, "cqtExpression"); LinqExpression = linqExpression; CqtExpression = cqtExpression; } internal readonly Expression LinqExpression; internal readonly CqtExpression CqtExpression; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] //--------------------------------------------------------------------- using CqtExpression = System.Data.Common.CommandTrees.DbExpression; using LinqExpression = System.Linq.Expressions.Expression; using System.Linq.Expressions; using System.Collections.ObjectModel; using System.Linq; using System.Collections.Generic; using System.Data.Common.CommandTrees; using System.Data.Metadata.Edm; using System.Reflection; using System.Data.Common.EntitySql; using System.Diagnostics; using System.Data.Common; using System.Globalization; namespace System.Data.Objects.ELinq { ////// Class containing binding information for an expression converter (associating CQT bindings /// with LINQ lambda parameter or LINQ sub-expressions) /// ////// Usage pattern: /// internal sealed class BindingContext { private readonly Stack/// BindingContext context = ...; /// /// // translate a "Where" lamba expression input.Where(i => i.X > 2); /// LambdaExpression whereLambda = ...; /// CqtExpression inputCqt = Translate(whereLambda.Arguments[1]); /// CqtExpression inputBinding = CreateExpressionBinding(inputCqt).Var; /// /// // push the scope defined by the parameter /// context.PushBindingScope(new KeyValuePair{ParameterExpression, CqtExpression}(whereLambda.Parameters[0], inputBinding)); /// /// // translate the expression in this context /// CqtExpression result = Translate(whereLambda.Expression); /// /// // pop the scope /// context.PopBindingScope(); ///
///_scopes; /// /// Initialize a new binding context /// internal BindingContext() { _scopes = new Stack(); } /// /// Set up a new binding scope where parameter expressions map to their paired CQT expressions. /// /// DbExpression/LinqExpression binding internal void PushBindingScope(Binding binding) { _scopes.Push(binding); } ////// Removes a scope when leaving a particular sub-expression. /// ///Scope. internal void PopBindingScope() { _scopes.Pop(); } internal bool TryGetBoundExpression(Expression linqExpression, out CqtExpression cqtExpression) { cqtExpression = _scopes .Where(binding => binding.LinqExpression == linqExpression) .Select(binding => binding.CqtExpression) .FirstOrDefault(); return cqtExpression != null; } } ////// Class describing a LINQ parameter and its bound expression. For instance, in /// /// products.Select(p => p.ID) /// /// the 'products' query is the bound expression, and 'p' is the parameter. /// internal sealed class Binding { internal Binding(Expression linqExpression, CqtExpression cqtExpression) { EntityUtil.CheckArgumentNull(linqExpression, "linqExpression"); EntityUtil.CheckArgumentNull(cqtExpression, "cqtExpression"); LinqExpression = linqExpression; CqtExpression = cqtExpression; } internal readonly Expression LinqExpression; internal readonly CqtExpression CqtExpression; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- WebPartConnectionsCloseVerb.cs
- SafeViewOfFileHandle.cs
- WhitespaceRuleReader.cs
- SimpleWebHandlerParser.cs
- TransformerInfo.cs
- WebPartConnection.cs
- WinFormsUtils.cs
- DataPager.cs
- SqlNamer.cs
- ClassicBorderDecorator.cs
- EventLogPermissionEntryCollection.cs
- dataprotectionpermission.cs
- StrongNameKeyPair.cs
- Rect3DConverter.cs
- Assembly.cs
- Viewport3DAutomationPeer.cs
- MetadataArtifactLoaderCompositeResource.cs
- EventLogPropertySelector.cs
- ErrorEventArgs.cs
- XPathPatternBuilder.cs
- CompensatableTransactionScopeActivityDesigner.cs
- RootAction.cs
- AnnotationDocumentPaginator.cs
- TaiwanLunisolarCalendar.cs
- ListManagerBindingsCollection.cs
- CounterSampleCalculator.cs
- RecordConverter.cs
- ClassHandlersStore.cs
- SubMenuStyle.cs
- ChangeBlockUndoRecord.cs
- Event.cs
- SemaphoreFullException.cs
- TraceLevelStore.cs
- dtdvalidator.cs
- SqlCacheDependencySection.cs
- MouseActionValueSerializer.cs
- MasterPageBuildProvider.cs
- DateBoldEvent.cs
- BitmapVisualManager.cs
- ConfigurationManagerHelper.cs
- ToolStripPanelRenderEventArgs.cs
- Function.cs
- ConstructorBuilder.cs
- InheritanceService.cs
- ModelPerspective.cs
- Geometry3D.cs
- OdbcConnectionHandle.cs
- DebugControllerThread.cs
- Win32PrintDialog.cs
- WebPartVerbsEventArgs.cs
- SortQuery.cs
- ResizeGrip.cs
- DiffuseMaterial.cs
- CaseCqlBlock.cs
- BStrWrapper.cs
- PeerUnsafeNativeMethods.cs
- TableRowCollection.cs
- SuppressMessageAttribute.cs
- UInt32Storage.cs
- ButtonFlatAdapter.cs
- CodeChecksumPragma.cs
- DefaultEventAttribute.cs
- Int64.cs
- DiscoveryViaBehavior.cs
- AppSecurityManager.cs
- HttpException.cs
- BitArray.cs
- NonVisualControlAttribute.cs
- ResourceWriter.cs
- TextPointerBase.cs
- KeyManager.cs
- NullReferenceException.cs
- ByteAnimation.cs
- AutoSizeToolBoxItem.cs
- Operator.cs
- LightweightCodeGenerator.cs
- PointAnimationUsingPath.cs
- MgmtConfigurationRecord.cs
- Vector3dCollection.cs
- PieceNameHelper.cs
- SecurityAlgorithmSuiteConverter.cs
- SimpleBitVector32.cs
- FontWeights.cs
- LoginUtil.cs
- StaticFileHandler.cs
- XmlDigitalSignatureProcessor.cs
- ProgressBar.cs
- DataGridLengthConverter.cs
- Token.cs
- XmlSchemaObjectTable.cs
- DesignerUtils.cs
- BitmapDecoder.cs
- ComponentEditorPage.cs
- TransformerConfigurationWizardBase.cs
- RectAnimationClockResource.cs
- ProjectionCamera.cs
- CompositeDataBoundControl.cs
- DeadCharTextComposition.cs
- PanelContainerDesigner.cs
- CodeAssignStatement.cs