I'm in need of a read lock for dapper, because I have one specific case when I need to read row from database and lock it and then perform some other operations.
This is how I call dapper:
protected async Task<List<T>> LoadData<T, U>(string sql, U parameters)
{
var rows = await getConnection().QueryAsync<T>(sql, parameters, commandType: CommandType.StoredProcedure, transaction: getTransaction());
return rows.ToList();
}
But no rows are locked. Interestingly transaction on saving data works just fine.
protected async Task<int> SaveData<U>(string sql, CommandType commandType, U parameters)
{
return await getConnection().ExecuteAsync(sql, parameters, commandType: commandType, transaction: getTransaction());
}
Connection is opened before calling dapper and transaction is started...like this:
if (connection.State != ConnectionState.Open)
connection.Open();
transaction = connection.BeginTransaction(IsolationLevel.Serializable);
SQL query is a plain select statement like this:
SELECT * FROM [dbo].[Tab01] WHERE [Id] = @Id