diff options
Diffstat (limited to 'projecttemplates/RelyingPartyLogic/Database.cs')
-rw-r--r-- | projecttemplates/RelyingPartyLogic/Database.cs | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/projecttemplates/RelyingPartyLogic/Database.cs b/projecttemplates/RelyingPartyLogic/Database.cs index 3dbb493..9ef72eb 100644 --- a/projecttemplates/RelyingPartyLogic/Database.cs +++ b/projecttemplates/RelyingPartyLogic/Database.cs @@ -51,7 +51,7 @@ namespace RelyingPartyLogic { throw; } - DataContextTransactionSimple = dataContext.Connection.BeginTransaction(); + DataContextTransaction = dataContext.Connection.BeginTransaction(); DataContextSimple = dataContext; } @@ -59,14 +59,14 @@ namespace RelyingPartyLogic { } } - private static DatabaseEntities DataContextSimple { + internal static IDbTransaction DataContextTransaction { get { if (HttpContext.Current != null) { - return HttpContext.Current.Items[DataContextKey] as DatabaseEntities; + return HttpContext.Current.Items[DataContextTransactionKey] as IDbTransaction; } else if (OperationContext.Current != null) { object data; - if (OperationContext.Current.IncomingMessageProperties.TryGetValue(DataContextKey, out data)) { - return data as DatabaseEntities; + if (OperationContext.Current.IncomingMessageProperties.TryGetValue(DataContextTransactionKey, out data)) { + return data as IDbTransaction; } else { return null; } @@ -75,25 +75,25 @@ namespace RelyingPartyLogic { } } - set { + private set { if (HttpContext.Current != null) { - HttpContext.Current.Items[DataContextKey] = value; + HttpContext.Current.Items[DataContextTransactionKey] = value; } else if (OperationContext.Current != null) { - OperationContext.Current.IncomingMessageProperties[DataContextKey] = value; + OperationContext.Current.IncomingMessageProperties[DataContextTransactionKey] = value; } else { throw new InvalidOperationException(); } } } - private static IDbTransaction DataContextTransactionSimple { + private static DatabaseEntities DataContextSimple { get { if (HttpContext.Current != null) { - return HttpContext.Current.Items[DataContextTransactionKey] as IDbTransaction; + return HttpContext.Current.Items[DataContextKey] as DatabaseEntities; } else if (OperationContext.Current != null) { object data; - if (OperationContext.Current.IncomingMessageProperties.TryGetValue(DataContextTransactionKey, out data)) { - return data as IDbTransaction; + if (OperationContext.Current.IncomingMessageProperties.TryGetValue(DataContextKey, out data)) { + return data as DatabaseEntities; } else { return null; } @@ -104,9 +104,9 @@ namespace RelyingPartyLogic { set { if (HttpContext.Current != null) { - HttpContext.Current.Items[DataContextTransactionKey] = value; + HttpContext.Current.Items[DataContextKey] = value; } else if (OperationContext.Current != null) { - OperationContext.Current.IncomingMessageProperties[DataContextTransactionKey] = value; + OperationContext.Current.IncomingMessageProperties[DataContextKey] = value; } else { throw new InvalidOperationException(); } @@ -126,10 +126,10 @@ namespace RelyingPartyLogic { } protected void Application_Error(object sender, EventArgs e) { - if (DataContextTransactionSimple != null) { - DataContextTransactionSimple.Rollback(); - DataContextTransactionSimple.Dispose(); - DataContextTransactionSimple = null; + if (DataContextTransaction != null) { + DataContextTransaction.Rollback(); + DataContextTransaction.Dispose(); + DataContextTransaction = null; } } @@ -137,9 +137,9 @@ namespace RelyingPartyLogic { var dataContext = DataContextSimple; if (dataContext != null) { dataContext.SaveChanges(); - if (DataContextTransactionSimple != null) { - DataContextTransactionSimple.Commit(); - DataContextTransactionSimple.Dispose(); + if (DataContextTransaction != null) { + DataContextTransaction.Commit(); + DataContextTransaction.Dispose(); } dataContext.Dispose(); |