c # – Async ExecuteNonQuery () implementation for IDBCommand vs SqlCommand.ExecuteNonQueryAsync

j & # 39; uses IDBCommand for my database layer in order to switch to other database providers that SqlDataProvider.

SqlCommand to all asynchronous methods like ExecuteNonQueryAsync but IDBCommand does not contain an asynchronous method.

In the future, we may need to change the data provider other than sql, I just can not use SqlCommand directly.

I'm just thinking of implementing my own Async versions. Would there be a performance problem if I implement mine? Or Better to use asynchronous methods implemented by Microsoft available for SqlCommand object?

In the following way, I implemented my async methods. The following is a synchronous:

public int ExecuteNonQuery (CommandType, typeType, string, commandText)
{
PrepareCommand (commandType, commandText);
var noOFRowsAffected = _dbCommand.ExecuteNonQuery ();
SetParameters (_dbCommand.Parameters);
return noOFRowsAffected;
}

What follows is the async version:

public asynchronous task ExecuteNonQueryAsync (Order Type, Order Type, Order Text String)
{
PrepareCommand (commandType, commandText);

var noOFRowsAffected = wait Task.Factory.StartNew (() =>
{
return _dbCommand.ExecuteNonQuery ();
});

SetParameters (_dbCommand.Parameters);
return noOFRowsAffected;
}

Please note that exception handling would be handled by the caller
layer.

Can someone give me the right direction? Is this a good way to do asynchronous operation or should I use Microsoft implemented SqlCommand to use his own methods? Any help is really appreciated. Thanks in advance 🙂