I am using MvcMiniProfiler 1.9 and LLBLGen Pro 3.5 SelfServicing with SqlServer 2012 and it works fine until I try to call a stored procedure. Then I get an error:
Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbCommand' to type 'System.Data.SqlClient.SqlCommand'.
Here is how I use it:
1. Created a custom DynamicQueryEngine:
public class ProfilingDynamicQueryEngine : DynamicQueryEngine
{
protected override DbCommand CreateCommand()
{
var cmd = base.CreateCommand();
return new ProfiledDbCommand(cmd, null, MiniProfiler.Current);
}
}
- Created a partial CommonDaoBase class:
public partial class CommonDaoBase
{
public CommonDaoBase(InheritanceHierarchyType typeOfInheritance, string entityName, IEntityFactory entityFactory)
: base(InheritanceInfoProviderSingleton.GetInstance(), new ProfilingDynamicQueryEngine(), typeOfInheritance, entityName, entityFactory)
{
}
public override DbConnection CreateConnection(string connectionString)
{
var dbConnection = base.CreateConnection(connectionString);
return new ProfiledDbConnection(dbConnection, MiniProfiler.Current);
}
}
- Called a stored procedure:
var dataTable = RetrievalProcedures.MyStoredProcedure();
Then I get an error in generated RetrievalProcedures file at this line:
DataTable toReturn = call.FillDataTable();
Error message is: Unable to cast object of type 'MvcMiniProfiler.Data.ProfiledDbCommand' to type 'System.Data.SqlClient.SqlCommand'.
Does anyone have any ideas why I am getting this error and how to fix it?