Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Objects / objectresult_tresulttype.cs / 1 / objectresult_tresulttype.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupowner [....] //--------------------------------------------------------------------- namespace System.Data.Objects { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Data.Metadata.Edm; using System.Data.Mapping; using System.Data.Objects.DataClasses; using System.Diagnostics; using System.Linq.Expressions; using System.Data.Common.Internal.Materialization; ////// This class implements IEnumerable of T and IDisposable. Instance of this class /// is returned from ObjectQuery<T>.Execute method. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] public sealed class ObjectResult: ObjectResult, IEnumerable { private Shaper _shaper; private DbDataReader _reader; private readonly EntitySet _singleEntitySet; private readonly TypeUsage _resultItemType; private IBindingList _cachedBindingList; internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType) { _shaper = shaper; _reader = _shaper.Reader; _singleEntitySet = singleEntitySet; _resultItemType = resultItemType; } private void EnsureCanEnumerateResults() { if (null == _shaper) { // Enumerating more than once is not allowed. throw EntityUtil.CannotReEnumerateQueryResults(); } } /// /// Returns an enumerator that iterates through the collection. /// public IEnumeratorGetEnumerator() { EnsureCanEnumerateResults(); Shaper shaper = _shaper; _shaper = null; IEnumerator result = shaper.GetEnumerator(); return result; } /// /// Performs tasks associated with freeing, releasing, or resetting resources. /// public override void Dispose() { DbDataReader reader = _reader; _reader = null; if (null != reader) { reader.Dispose(); } if (_shaper != null) { // This case includes when the ObjectResult is disposed before it // created an ObjectQueryEnumeration; at this time, the connection can be released if (_shaper.Context != null) { _shaper.Context.ReleaseConnection(); } _shaper = null; } } internal override IEnumerator GetEnumeratorInternal() { return ((IEnumerable)this).GetEnumerator(); } internal override IList GetIListSourceListInternal() { // You can only enumerate the query results once, and the creation of an ObjectView consumes this enumeration. // However, there are situations where setting the DataSource of a control can result in multiple calls to this method. // In order to enable this scenario and allow direct binding to the ObjectResult instance, // the ObjectView is cached and returned on subsequent calls to this method. if (_cachedBindingList == null) { EnsureCanEnumerateResults(); bool forceReadOnly = this._shaper.MergeOption == MergeOption.NoTracking; _cachedBindingList = ObjectViewFactory.CreateViewForQuery (this._resultItemType, this, this._shaper.Context, forceReadOnly, this._singleEntitySet); } return _cachedBindingList; } public override Type ElementType { get { return typeof(T); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupowner [....] //--------------------------------------------------------------------- namespace System.Data.Objects { using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Data; using System.Data.Common; using System.Data.Metadata.Edm; using System.Data.Mapping; using System.Data.Objects.DataClasses; using System.Diagnostics; using System.Linq.Expressions; using System.Data.Common.Internal.Materialization; ////// This class implements IEnumerable of T and IDisposable. Instance of this class /// is returned from ObjectQuery<T>.Execute method. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")] public sealed class ObjectResult: ObjectResult, IEnumerable { private Shaper _shaper; private DbDataReader _reader; private readonly EntitySet _singleEntitySet; private readonly TypeUsage _resultItemType; private IBindingList _cachedBindingList; internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType) { _shaper = shaper; _reader = _shaper.Reader; _singleEntitySet = singleEntitySet; _resultItemType = resultItemType; } private void EnsureCanEnumerateResults() { if (null == _shaper) { // Enumerating more than once is not allowed. throw EntityUtil.CannotReEnumerateQueryResults(); } } /// /// Returns an enumerator that iterates through the collection. /// public IEnumeratorGetEnumerator() { EnsureCanEnumerateResults(); Shaper shaper = _shaper; _shaper = null; IEnumerator result = shaper.GetEnumerator(); return result; } /// /// Performs tasks associated with freeing, releasing, or resetting resources. /// public override void Dispose() { DbDataReader reader = _reader; _reader = null; if (null != reader) { reader.Dispose(); } if (_shaper != null) { // This case includes when the ObjectResult is disposed before it // created an ObjectQueryEnumeration; at this time, the connection can be released if (_shaper.Context != null) { _shaper.Context.ReleaseConnection(); } _shaper = null; } } internal override IEnumerator GetEnumeratorInternal() { return ((IEnumerable)this).GetEnumerator(); } internal override IList GetIListSourceListInternal() { // You can only enumerate the query results once, and the creation of an ObjectView consumes this enumeration. // However, there are situations where setting the DataSource of a control can result in multiple calls to this method. // In order to enable this scenario and allow direct binding to the ObjectResult instance, // the ObjectView is cached and returned on subsequent calls to this method. if (_cachedBindingList == null) { EnsureCanEnumerateResults(); bool forceReadOnly = this._shaper.MergeOption == MergeOption.NoTracking; _cachedBindingList = ObjectViewFactory.CreateViewForQuery (this._resultItemType, this, this._shaper.Context, forceReadOnly, this._singleEntitySet); } return _cachedBindingList; } public override Type ElementType { get { return typeof(T); } } } } // 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
- VisualStates.cs
- DbConnectionStringCommon.cs
- cache.cs
- CodeDirectoryCompiler.cs
- FaultHandlingFilter.cs
- Image.cs
- EditorPart.cs
- ComponentCommands.cs
- NameTable.cs
- XPathCompileException.cs
- MenuItemAutomationPeer.cs
- RunWorkerCompletedEventArgs.cs
- ThicknessKeyFrameCollection.cs
- EraserBehavior.cs
- MD5CryptoServiceProvider.cs
- ServiceOperationHelpers.cs
- BitmapEffectCollection.cs
- JoinSymbol.cs
- PeerContact.cs
- ProjectionPruner.cs
- ToolStripSeparator.cs
- Popup.cs
- CqlParserHelpers.cs
- QualifiedCellIdBoolean.cs
- CodeTypeMemberCollection.cs
- DataTableCollection.cs
- FontInfo.cs
- DebugController.cs
- TextRangeBase.cs
- XdrBuilder.cs
- ConfigurationLocation.cs
- CodeCommentStatement.cs
- _NestedSingleAsyncResult.cs
- NetTcpBinding.cs
- ToolStripContainerActionList.cs
- PhysicalAddress.cs
- SecurityHelper.cs
- AssemblyNameEqualityComparer.cs
- TextBoxLine.cs
- NameValueCollection.cs
- TraceInternal.cs
- CodeSnippetStatement.cs
- ComponentCollection.cs
- IPipelineRuntime.cs
- FolderBrowserDialog.cs
- LabelTarget.cs
- HotSpotCollection.cs
- CompilerTypeWithParams.cs
- ExecutedRoutedEventArgs.cs
- Double.cs
- Pkcs9Attribute.cs
- DependencyPropertyHelper.cs
- BindingList.cs
- ValidationManager.cs
- CategoryList.cs
- ClientProxyGenerator.cs
- Dump.cs
- WorkflowLayouts.cs
- CqlParser.cs
- ErrorEventArgs.cs
- UriWriter.cs
- TextParagraph.cs
- HtmlImage.cs
- DefaultDialogButtons.cs
- ObjectQueryState.cs
- TextRenderer.cs
- HttpModuleActionCollection.cs
- CubicEase.cs
- RijndaelManaged.cs
- EventDriven.cs
- Matrix.cs
- PagedDataSource.cs
- ButtonColumn.cs
- LinearKeyFrames.cs
- OrderedDictionary.cs
- CodeFieldReferenceExpression.cs
- HelpEvent.cs
- EntitySetDataBindingList.cs
- SmtpNtlmAuthenticationModule.cs
- ActivationServices.cs
- PanelStyle.cs
- XsdDataContractImporter.cs
- BrowserCapabilitiesCompiler.cs
- SerializationSectionGroup.cs
- CssTextWriter.cs
- DesignerMetadata.cs
- DataGridViewSelectedRowCollection.cs
- SelectionEditingBehavior.cs
- ExtensionQuery.cs
- recordstatescratchpad.cs
- PipeSecurity.cs
- ListViewInsertedEventArgs.cs
- MachinePropertyVariants.cs
- SvcMapFile.cs
- SystemException.cs
- MsmqAppDomainProtocolHandler.cs
- OleDbPropertySetGuid.cs
- ExceptionCollection.cs
- OperationAbortedException.cs
- ProfileSettingsCollection.cs