私はvb.netの男で、C#を読むのが苦手です。C# Dapper を DLL にコンパイルし、アプリで使用しました。私の主な懸念は、各 SQL クエリで SQL Azure の一時的な障害処理フレームワークを既定で統合するようにソースを変更する必要があると思うことです。
接続レベルで再試行ロジックを追加できます。これは、dapper の最上位にあるためですが、drapper クラスに埋め込まれている実行クエリ レベルでは追加できません。
誰もそれをまだやっていますか?
* アップデート *
Dapper 呼び出しの上に ReliableSqlConnection のみを使用すると、クエリ以外の実行で再試行ロジックが処理されますか?
これは、transietn fault hanling を使用した MS からのリトライのサンプル コードです。
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage;
using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure;
using System.Data;
...
using (ReliableSqlConnection conn = new ReliableSqlConnection(connString, retryPolicy))
{
conn.Open();
IDbCommand selectCommand = conn.CreateCommand();
selectCommand.CommandText =
"UPDATE Application SET [DateUpdated] = getdate()";
// Execute the above query using a retry-aware ExecuteCommand method which
// will automatically retry if the query has failed (or connection was
// dropped).
int recordsAffected = conn.ExecuteCommand(selectCommand, retryPolicy);
}
これはDapperコードの実行部分です。同じ名前が使用されていますが、カスタム実行関数だと思います
private static int ExecuteCommand(IDbConnection cnn, IDbTransaction transaction, string sql, Action<IDbCommand, object> paramReader, object obj, int? commandTimeout, CommandType? commandType)
{
IDbCommand cmd = null;
bool wasClosed = cnn.State == ConnectionState.Closed;
try
{
cmd = SetupCommand(cnn, transaction, sql, paramReader, obj, commandTimeout, commandType);
if (wasClosed) cnn.Open();
return cmd.ExecuteNonQuery();
}
finally
{
if (wasClosed) cnn.Close();
if (cmd != null) cmd.Dispose();
}
}