summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-12-16 23:01:24 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2009-12-16 23:01:24 -0800
commit82e588d5309012b0fc729b205f9c0d17d1347fdd (patch)
tree138f91138e3151e373ac8ae9f852a40ecfe0ec24
parent5293721eabaa66854d9f66871ef5e9df727e5553 (diff)
downloadDotNetOpenAuth-82e588d5309012b0fc729b205f9c0d17d1347fdd.zip
DotNetOpenAuth-82e588d5309012b0fc729b205f9c0d17d1347fdd.tar.gz
DotNetOpenAuth-82e588d5309012b0fc729b205f9c0d17d1347fdd.tar.bz2
Fixed stored proc execution that is missing a contextual transaction, leading to runtime errors.
-rw-r--r--projecttemplates/RelyingPartyLogic/Database.cs42
-rw-r--r--projecttemplates/RelyingPartyLogic/Utilities.cs1
2 files changed, 22 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();
diff --git a/projecttemplates/RelyingPartyLogic/Utilities.cs b/projecttemplates/RelyingPartyLogic/Utilities.cs
index 7a8f31b..bbcfc68 100644
--- a/projecttemplates/RelyingPartyLogic/Utilities.cs
+++ b/projecttemplates/RelyingPartyLogic/Utilities.cs
@@ -110,6 +110,7 @@ GO
}
DbCommand cmd = connection.CreateCommand();
+ cmd.Transaction = (DbTransaction)Database.DataContextTransaction;
cmd.CommandText = command;
cmd.CommandType = CommandType.StoredProcedure;
try {