Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Objects / objectresult_tresulttype.cs / 1305376 / 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 readonly bool _readerOwned; private IBindingList _cachedBindingList; internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType) : this(shaper, singleEntitySet, resultItemType, true) { } internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType, bool readerOwned) { _shaper = shaper; _reader = _shaper.Reader; _singleEntitySet = singleEntitySet; _resultItemType = resultItemType; _readerOwned = readerOwned; } 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 && _readerOwned) { 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 && _readerOwned) { _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 readonly bool _readerOwned; private IBindingList _cachedBindingList; internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType) : this(shaper, singleEntitySet, resultItemType, true) { } internal ObjectResult(Shaper shaper, EntitySet singleEntitySet, TypeUsage resultItemType, bool readerOwned) { _shaper = shaper; _reader = _shaper.Reader; _singleEntitySet = singleEntitySet; _resultItemType = resultItemType; _readerOwned = readerOwned; } 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 && _readerOwned) { 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 && _readerOwned) { _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
- _Win32.cs
- DeviceContexts.cs
- RepeaterCommandEventArgs.cs
- XmlMapping.cs
- BuilderInfo.cs
- HttpApplicationFactory.cs
- PinnedBufferMemoryStream.cs
- ChangeToolStripParentVerb.cs
- EventLogEntry.cs
- GifBitmapEncoder.cs
- XPathNodePointer.cs
- ThreadAttributes.cs
- AccessViolationException.cs
- AppLevelCompilationSectionCache.cs
- ResXResourceSet.cs
- Exceptions.cs
- FlowDocumentScrollViewer.cs
- DataGridViewCellLinkedList.cs
- ProcessInfo.cs
- TablePattern.cs
- WebPartEventArgs.cs
- XmlSchemaObjectTable.cs
- InvalidCastException.cs
- Zone.cs
- XmlDictionaryWriter.cs
- IxmlLineInfo.cs
- NameSpaceExtractor.cs
- NativeMethods.cs
- GridViewRowPresenter.cs
- CommandBindingCollection.cs
- Stacktrace.cs
- DatagridviewDisplayedBandsData.cs
- ScaleTransform.cs
- Trigger.cs
- LOSFormatter.cs
- DrawingCollection.cs
- ApplicationCommands.cs
- UdpChannelFactory.cs
- TreeNode.cs
- SamlAuthorityBinding.cs
- DesignerTransaction.cs
- EntityDataSourceConfigureObjectContext.cs
- DynamicFilterExpression.cs
- SchemaCollectionCompiler.cs
- DiscoveryClientRequestChannel.cs
- NameValueConfigurationElement.cs
- GlobalProxySelection.cs
- BoundPropertyEntry.cs
- TypefaceMap.cs
- ToolStripArrowRenderEventArgs.cs
- TextParagraphCache.cs
- TagPrefixInfo.cs
- CounterCreationDataCollection.cs
- SourceExpressionException.cs
- TextParagraphView.cs
- IUnknownConstantAttribute.cs
- ImageSourceConverter.cs
- XslTransform.cs
- TextHintingModeValidation.cs
- WebRequestModulesSection.cs
- Byte.cs
- OracleCommandSet.cs
- RegexReplacement.cs
- CultureMapper.cs
- Graph.cs
- AnimationLayer.cs
- DiscoveryClientChannelFactory.cs
- CatchBlock.cs
- GlyphingCache.cs
- _ListenerAsyncResult.cs
- HttpPostProtocolImporter.cs
- XmlCharCheckingWriter.cs
- AppDomainFactory.cs
- cookie.cs
- IndependentAnimationStorage.cs
- SafeHandle.cs
- _UncName.cs
- ClickablePoint.cs
- ViewManager.cs
- PagePropertiesChangingEventArgs.cs
- ArrangedElementCollection.cs
- MessageAction.cs
- CaseInsensitiveComparer.cs
- AnnotationAdorner.cs
- BindableTemplateBuilder.cs
- CodeDirectionExpression.cs
- ClientSideProviderDescription.cs
- StateRuntime.cs
- XmlWrappingReader.cs
- PeerToPeerException.cs
- HatchBrush.cs
- SelectedGridItemChangedEvent.cs
- StaticFileHandler.cs
- BamlLocalizerErrorNotifyEventArgs.cs
- SineEase.cs
- HttpServerVarsCollection.cs
- PropertyChangingEventArgs.cs
- RequiredAttributeAttribute.cs
- DbParameterCollection.cs
- ADMembershipUser.cs