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 / EntityClient / EntityTransaction.cs / 1 / EntityTransaction.cs
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
namespace System.Data.EntityClient
{
using Metadata.Edm;
///
/// Class representing a transaction for the conceptual layer
///
public sealed class EntityTransaction : DbTransaction
{
private EntityConnection _connection;
private DbTransaction _storeTransaction;
///
/// Constructs the EntityTransaction object with an associated connection and the underlying store transaction
///
/// The EntityConnetion object owning this transaction
/// The underlying transaction object
internal EntityTransaction(EntityConnection connection, DbTransaction storeTransaction)
: base()
{
Debug.Assert(connection != null && storeTransaction != null);
this._connection = connection;
this._storeTransaction = storeTransaction;
}
///
/// The connection object owning this transaction object
///
public new EntityConnection Connection
{
get
{ // follow the store transaction behavior
return ((null != _storeTransaction.Connection) ? _connection : null);
}
}
///
/// The connection object owning this transaction object
///
protected override DbConnection DbConnection
{
get
{ // follow the store transaction behavior
return ((null != _storeTransaction.Connection) ? _connection : null);
}
}
///
/// The isolation level of this transaction
///
public override IsolationLevel IsolationLevel
{
get
{
return this._storeTransaction.IsolationLevel;
}
}
///
/// Gets the DbTransaction for the underlying provider transaction
///
internal DbTransaction StoreTransaction
{
get
{
return this._storeTransaction;
}
}
///
/// Commits the transaction
///
public override void Commit()
{
try
{
this._storeTransaction.Commit();
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.Provider(@"Commit", e);
}
throw;
}
this.ClearCurrentTransaction();
}
///
/// Rolls back the transaction
///
public override void Rollback()
{
try
{
this._storeTransaction.Rollback();
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.Provider(@"Rollback", e);
}
throw;
}
this.ClearCurrentTransaction();
}
///
/// Cleans up this transaction object
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.ClearCurrentTransaction();
this._storeTransaction.Dispose();
}
base.Dispose(disposing);
}
///
/// Helper method to wrap EntityConnection.ClearCurrentTransaction()
///
private void ClearCurrentTransaction()
{
if (_connection.CurrentTransaction == this)
{
_connection.ClearCurrentTransaction();
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//----------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// @owner [....], [....]
//---------------------------------------------------------------------
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
namespace System.Data.EntityClient
{
using Metadata.Edm;
///
/// Class representing a transaction for the conceptual layer
///
public sealed class EntityTransaction : DbTransaction
{
private EntityConnection _connection;
private DbTransaction _storeTransaction;
///
/// Constructs the EntityTransaction object with an associated connection and the underlying store transaction
///
/// The EntityConnetion object owning this transaction
/// The underlying transaction object
internal EntityTransaction(EntityConnection connection, DbTransaction storeTransaction)
: base()
{
Debug.Assert(connection != null && storeTransaction != null);
this._connection = connection;
this._storeTransaction = storeTransaction;
}
///
/// The connection object owning this transaction object
///
public new EntityConnection Connection
{
get
{ // follow the store transaction behavior
return ((null != _storeTransaction.Connection) ? _connection : null);
}
}
///
/// The connection object owning this transaction object
///
protected override DbConnection DbConnection
{
get
{ // follow the store transaction behavior
return ((null != _storeTransaction.Connection) ? _connection : null);
}
}
///
/// The isolation level of this transaction
///
public override IsolationLevel IsolationLevel
{
get
{
return this._storeTransaction.IsolationLevel;
}
}
///
/// Gets the DbTransaction for the underlying provider transaction
///
internal DbTransaction StoreTransaction
{
get
{
return this._storeTransaction;
}
}
///
/// Commits the transaction
///
public override void Commit()
{
try
{
this._storeTransaction.Commit();
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.Provider(@"Commit", e);
}
throw;
}
this.ClearCurrentTransaction();
}
///
/// Rolls back the transaction
///
public override void Rollback()
{
try
{
this._storeTransaction.Rollback();
}
catch (Exception e)
{
if (EntityUtil.IsCatchableExceptionType(e))
{
throw EntityUtil.Provider(@"Rollback", e);
}
throw;
}
this.ClearCurrentTransaction();
}
///
/// Cleans up this transaction object
///
/// true to release both managed and unmanaged resources; false to release only unmanaged resources
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.ClearCurrentTransaction();
this._storeTransaction.Dispose();
}
base.Dispose(disposing);
}
///
/// Helper method to wrap EntityConnection.ClearCurrentTransaction()
///
private void ClearCurrentTransaction()
{
if (_connection.CurrentTransaction == this)
{
_connection.ClearCurrentTransaction();
}
}
}
}
// 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
- EncodingDataItem.cs
- BaseServiceProvider.cs
- DbModificationCommandTree.cs
- DES.cs
- CssClassPropertyAttribute.cs
- TaiwanLunisolarCalendar.cs
- WebPartCloseVerb.cs
- StyleModeStack.cs
- ThreadInterruptedException.cs
- PositiveTimeSpanValidator.cs
- Win32Interop.cs
- InputScope.cs
- PropertyItem.cs
- MonthChangedEventArgs.cs
- DesignerActionGlyph.cs
- RangeBase.cs
- Application.cs
- SimpleWebHandlerParser.cs
- ClrPerspective.cs
- EffectiveValueEntry.cs
- ExpressionBindings.cs
- DependencyPropertyKey.cs
- SmiGettersStream.cs
- recordstate.cs
- HotSpotCollection.cs
- AttributeQuery.cs
- Win32Exception.cs
- RtfToken.cs
- UIElementCollection.cs
- SafeNativeMethods.cs
- Literal.cs
- MetadataArtifactLoader.cs
- TagMapCollection.cs
- SqlClientWrapperSmiStream.cs
- BitVector32.cs
- StreamWithDictionary.cs
- GridLength.cs
- ClientSettingsStore.cs
- ModifierKeysConverter.cs
- ValidationHelpers.cs
- AutoCompleteStringCollection.cs
- Invariant.cs
- BufferAllocator.cs
- TemplateManager.cs
- CloudCollection.cs
- FrameDimension.cs
- VirtualizingStackPanel.cs
- ADConnectionHelper.cs
- PlainXmlDeserializer.cs
- PeerContact.cs
- DataGridViewRow.cs
- ConfigXmlSignificantWhitespace.cs
- ScrollBar.cs
- ServiceNameElement.cs
- DataColumnMappingCollection.cs
- SettingsContext.cs
- SafeFindHandle.cs
- SqlBulkCopyColumnMapping.cs
- CodeDefaultValueExpression.cs
- UnicastIPAddressInformationCollection.cs
- GridView.cs
- Win32Exception.cs
- CellConstant.cs
- XmlSchemaIdentityConstraint.cs
- TrustDriver.cs
- OdbcRowUpdatingEvent.cs
- DataGridItemCollection.cs
- selecteditemcollection.cs
- __Error.cs
- SvcMapFileSerializer.cs
- MD5CryptoServiceProvider.cs
- CanonicalXml.cs
- DataGridColumnHeader.cs
- StringValueSerializer.cs
- DeploymentExceptionMapper.cs
- DesigntimeLicenseContext.cs
- ColumnHeaderConverter.cs
- StorageRoot.cs
- TraceSection.cs
- EntityDataSourceValidationException.cs
- DataStreams.cs
- Site.cs
- SystemPens.cs
- SeverityFilter.cs
- ThreadExceptionEvent.cs
- NullableFloatSumAggregationOperator.cs
- DNS.cs
- EndPoint.cs
- Emitter.cs
- SerializationSectionGroup.cs
- CompatibleIComparer.cs
- FragmentQuery.cs
- CompensatableTransactionScopeActivityDesigner.cs
- GridViewUpdateEventArgs.cs
- AutoGeneratedField.cs
- DataGridViewComboBoxCell.cs
- TextEditorCharacters.cs
- EdmSchemaAttribute.cs
- ByteStorage.cs
- DatatypeImplementation.cs