Can I have more than one profiled connection with MVC Mini Profiler?

asp.net-mvc-3 dapper entity-framework-4 mvc-mini-profiler

Question

I'd like to use a mixture of both Dapper and EF 4 in my MVC3 application. Is it possible to have more than one profiled connection, or share a profiled connection?

Accepted Answer

Yes, you can use the EF profiled connection with Dapper, here's what I ended up using.

    private static DatabaseContext GetDatabaseContext()
    {
        using (MiniProfiler.Current.Step("Create Oracle EF Context"))
        {
            var pConn = ProfiledConnection;
            return pConn.CreateObjectContext<DatabaseContext>();
        }
    }

    private static EFProfiledDbConnection ProfiledConnection
    {
        get
        {
            using (MiniProfiler.Current.Step("Create Oracle Profiled Connection"))
            {
                var connectionString =
                    ConfigurationManager.ConnectionStrings["DatabaseContext"].ConnectionString;
                var ecsb = new EntityConnectionStringBuilder(connectionString);
                var oraConn = new OracleConnection(ecsb.ProviderConnectionString);
                var pConn = new EFProfiledDbConnection(oraConn, MiniProfiler.Current);
                return pConn;
            }
        }
    }

Then I used them in this way

            using (var ctx = GetDatabaseContext())
            {
                var result = ctx.SOME_EF_ENTITY.FirstOrDefault(c => c.LOGINNAME == username && c.PASSWORD == password);


                return result;
            }

and

        const string sql = @"
                    SELECT ppro_status_code_id 
                    FROM   ppro_status_codes 
                    WHERE  table_name = 'CLIENT_FC_SHARED' 
                        AND status_code = :status_code";

        using (var cnn = ProfiledConnection)
        {
            cnn.Open();

            var data = cnn.Query<dynamic>(sql, new { status_code = code });
            var result = data.First();
            var codeID = result.PPRO_STATUS_CODE_ID;
            return codeID;
        }



Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why