diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-07 08:54:52 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-01-07 08:54:52 -0800 |
commit | 1767c767e5e52cb28cf8e0bdeebdfe051caa1fd2 (patch) | |
tree | fd31e926fdfd22ec8819469a23b743d4253c07b0 /projecttemplates/RelyingPartyLogic/Utilities.cs | |
parent | 36bb738e4cc937a8b04321ef85b098d16d0793c8 (diff) | |
parent | bbbebebce7d9306c48247f44be5b649c908b7a67 (diff) | |
download | DotNetOpenAuth-1767c767e5e52cb28cf8e0bdeebdfe051caa1fd2.zip DotNetOpenAuth-1767c767e5e52cb28cf8e0bdeebdfe051caa1fd2.tar.gz DotNetOpenAuth-1767c767e5e52cb28cf8e0bdeebdfe051caa1fd2.tar.bz2 |
Merge branch 'v3.3'
Diffstat (limited to 'projecttemplates/RelyingPartyLogic/Utilities.cs')
-rw-r--r-- | projecttemplates/RelyingPartyLogic/Utilities.cs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/projecttemplates/RelyingPartyLogic/Utilities.cs b/projecttemplates/RelyingPartyLogic/Utilities.cs index bbcfc68..57a1baa 100644 --- a/projecttemplates/RelyingPartyLogic/Utilities.cs +++ b/projecttemplates/RelyingPartyLogic/Utilities.cs @@ -96,21 +96,38 @@ GO } } + public static int ExecuteCommand(this ObjectContext objectContext, string command) { + // Try to automatically add the appropriate transaction if one is known. + EntityTransaction transaction = null; + if (Database.IsDataContextInitialized && Database.DataContext == objectContext) { + transaction = Database.DataContextTransaction; + } + return ExecuteCommand(objectContext, transaction, command); + } + /// <summary> /// Executes a SQL command against the SQL connection. /// </summary> /// <param name="objectContext">The object context.</param> + /// <param name="transaction">The transaction to use, if any.</param> /// <param name="command">The command to execute.</param> /// <returns>The result of executing the command.</returns> - public static int ExecuteCommand(this ObjectContext objectContext, string command) { - DbConnection connection = ((EntityConnection)objectContext.Connection).StoreConnection; - bool opening = (connection.State == ConnectionState.Closed); + public static int ExecuteCommand(this ObjectContext objectContext, EntityTransaction transaction, string command) { + if (objectContext == null) { + throw new ArgumentNullException("objectContext"); + } + if (String.IsNullOrEmpty(command)) { + throw new ArgumentNullException("command"); + } + + DbConnection connection = (EntityConnection)objectContext.Connection; + bool opening = connection.State == ConnectionState.Closed; if (opening) { connection.Open(); } DbCommand cmd = connection.CreateCommand(); - cmd.Transaction = (DbTransaction)Database.DataContextTransaction; + cmd.Transaction = transaction; cmd.CommandText = command; cmd.CommandType = CommandType.StoredProcedure; try { |