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
- ControlType.cs
- PolyLineSegment.cs
- ToolboxItemWrapper.cs
- GroupBox.cs
- OneToOneMappingSerializer.cs
- ProfessionalColorTable.cs
- CommonRemoteMemoryBlock.cs
- SerializableTypeCodeDomSerializer.cs
- ObjectViewFactory.cs
- ConsoleTraceListener.cs
- PagerSettings.cs
- FixedSOMTextRun.cs
- DataGridViewSortCompareEventArgs.cs
- WebPartZoneCollection.cs
- DataListDesigner.cs
- TrustLevelCollection.cs
- ProfilePropertySettings.cs
- DataRecordObjectView.cs
- GridViewPageEventArgs.cs
- GridViewSortEventArgs.cs
- PathFigure.cs
- TemplateXamlTreeBuilder.cs
- ManualWorkflowSchedulerService.cs
- RuntimeConfigLKG.cs
- TextBox.cs
- CollectionContainer.cs
- DataGridRowHeader.cs
- Classification.cs
- MdImport.cs
- IISMapPath.cs
- RegexEditorDialog.cs
- HtmlDocument.cs
- HwndKeyboardInputProvider.cs
- XmlWrappingReader.cs
- InkCanvasAutomationPeer.cs
- CompilationUtil.cs
- SafeNativeMethodsMilCoreApi.cs
- formatstringdialog.cs
- XmlTypeAttribute.cs
- XmlBindingWorker.cs
- SQLBinaryStorage.cs
- XmlSchemaNotation.cs
- GenericArgumentsUpdater.cs
- DelayedRegex.cs
- WebControlsSection.cs
- TableStyle.cs
- FormViewDeletedEventArgs.cs
- MessageEnumerator.cs
- SessionStateItemCollection.cs
- SqlAliasesReferenced.cs
- EditorAttribute.cs
- BooleanConverter.cs
- ManualResetEvent.cs
- WebPartEditorApplyVerb.cs
- OleDbStruct.cs
- SchemaContext.cs
- PtsPage.cs
- CodeAttributeDeclaration.cs
- ViewGenerator.cs
- SoapMessage.cs
- AssemblyEvidenceFactory.cs
- UInt16Storage.cs
- _DomainName.cs
- PropertyTabAttribute.cs
- ConnectionConsumerAttribute.cs
- FilteredSchemaElementLookUpTable.cs
- WS2007HttpBindingCollectionElement.cs
- DataControlPagerLinkButton.cs
- AssociationTypeEmitter.cs
- ExtensionSimplifierMarkupObject.cs
- MemberExpression.cs
- EventHandlerList.cs
- NavigationWindowAutomationPeer.cs
- Calendar.cs
- SoapCommonClasses.cs
- XmlTextReaderImplHelpers.cs
- DataViewListener.cs
- SoapElementAttribute.cs
- HashCodeCombiner.cs
- DrawingState.cs
- XamlTemplateSerializer.cs
- CustomSignedXml.cs
- BaseTypeViewSchema.cs
- RegexCode.cs
- ToolStripAdornerWindowService.cs
- RectValueSerializer.cs
- ISessionStateStore.cs
- QuaternionKeyFrameCollection.cs
- Context.cs
- SystemResources.cs
- CodeTypeDeclarationCollection.cs
- ConnectionConsumerAttribute.cs
- ApplicationSecurityManager.cs
- GenericXmlSecurityToken.cs
- Logging.cs
- BaseTemplateBuildProvider.cs
- ToolStrip.cs
- TraceHandlerErrorFormatter.cs
- SwitchAttribute.cs
- CqlParserHelpers.cs