You can try something like this.
Database db = DatabaseFactory.CreateDatabase();
DbCommand dbCommand = db.GetStoredProcCommand(PROC);
ProfiledDbCommand cmd = new ProfiledDbCommand(dbCommand, dbCommand.Connection, MvcMiniProfiler.MiniProfiler.Current);
db.AddInParameter(cmd, "foo", DbType.Int64, 0);
DbConnection dbc = MvcMiniProfiler.Data.ProfiledDbConnection.Get(dbCommand.Connection, MiniProfiler.Current);
DataSet ds = db.ExecuteDataSet(dbc);
Update :
After a lot of searching though the EntLib Data source code, The SqlDatabase, it's doesn't look like there is really an easy way to achive this. Sorry. I know I am.
This actually seems to be an issue with Mvc-Mini-Profiler. If you look at this Issues 19 Link on MVC-Mini-Profiler Project Home, you will see other people are having the same Issue.
I've spent quite a while going though System.Data.SqlClient with Reflector, and ProfiledDbProviderFactory, trying to see what the Issue is and it seems like the following is were the problem is. This is found in ProfiledDbProviderFactory class.
public override DbDataAdapter CreateDataAdapter()
{
return tail.CreateDataAdapter();
}
Now the problem isn't exactly with this code but the fact that when Microsoft.Practices.EnterpriseLibrary.Data.Database
class calls an intance of DbDataAdapter
(tail in our case is SqlClientFactory) it creates SqlClientFactory Command
, and then tries to set the Connection
of this command to ProfiledDbConnection
and this is were it breaks.
I've tried creating my own Factory classes to get around this but I just get too lost. Maybe when I have some free time I will try and sort this out, unless SO team beats me to it. :)