Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- TaskFormBase.cs
- EdmTypeAttribute.cs
- RelationshipEnd.cs
- ItemCheckedEvent.cs
- BinaryUtilClasses.cs
- FileResponseElement.cs
- GuidConverter.cs
- StyleTypedPropertyAttribute.cs
- CacheForPrimitiveTypes.cs
- EmptyControlCollection.cs
- reliableinputsessionchannel.cs
- OutOfProcStateClientManager.cs
- ToolStripPanelCell.cs
- Label.cs
- TrailingSpaceComparer.cs
- SqlCommandBuilder.cs
- InputProcessorProfiles.cs
- SizeConverter.cs
- DataRowExtensions.cs
- IPipelineRuntime.cs
- PersistenceParticipant.cs
- TimerEventSubscriptionCollection.cs
- DesignerOptions.cs
- DataViewSettingCollection.cs
- DataTableReaderListener.cs
- DataRowCollection.cs
- ComponentSerializationService.cs
- HttpBrowserCapabilitiesBase.cs
- WorkflowControlEndpoint.cs
- Menu.cs
- MetadataArtifactLoaderCompositeResource.cs
- SecurityTokenValidationException.cs
- SystemTcpConnection.cs
- DataObjectPastingEventArgs.cs
- FacetValues.cs
- shaperfactoryquerycacheentry.cs
- remotingproxy.cs
- SmtpCommands.cs
- StreamingContext.cs
- PeerTransportListenAddressConverter.cs
- TextSpanModifier.cs
- KeyConverter.cs
- XmlSerializationGeneratedCode.cs
- TableCell.cs
- WeakReference.cs
- WindowsScroll.cs
- OnOperation.cs
- XmlSchemaGroup.cs
- Quaternion.cs
- QueryGenerator.cs
- TreeViewCancelEvent.cs
- XPathConvert.cs
- DesignerActionUIService.cs
- StringComparer.cs
- SingleKeyFrameCollection.cs
- Terminate.cs
- DataTemplateKey.cs
- TreeViewAutomationPeer.cs
- StreamUpgradeInitiator.cs
- ColorConverter.cs
- MetadataFile.cs
- ConstantCheck.cs
- TrackingMemoryStream.cs
- CacheHelper.cs
- ProxyHelper.cs
- ServiceHostFactory.cs
- OdbcUtils.cs
- TypeInfo.cs
- ByteStreamMessageEncoderFactory.cs
- Walker.cs
- EntryPointNotFoundException.cs
- CustomAttributeFormatException.cs
- HttpWebResponse.cs
- StateManagedCollection.cs
- SchemaName.cs
- ProcessHostConfigUtils.cs
- ProgressBarAutomationPeer.cs
- PassportAuthenticationEventArgs.cs
- PropertyMetadata.cs
- DbConnectionPoolCounters.cs
- HwndKeyboardInputProvider.cs
- PasswordDeriveBytes.cs
- TileBrush.cs
- DataGridViewCellStyleChangedEventArgs.cs
- WebColorConverter.cs
- MemoryPressure.cs
- JsonDataContract.cs
- Matrix3DValueSerializer.cs
- TagPrefixInfo.cs
- NetDataContractSerializer.cs
- ControlPersister.cs
- WS2007HttpBindingCollectionElement.cs
- ExpressionConverter.cs
- ProviderUtil.cs
- WebBrowserHelper.cs
- XhtmlStyleClass.cs
- CanonicalFormWriter.cs
- Double.cs
- SQLStringStorage.cs
- AttributeUsageAttribute.cs