public void TestProfiledStoredProcWithParameters() { using (var connection = ConnectionWithTransaction()) { connection.ExecuteSql("CREATE PROC InsightTestProcMiniProfiler (@Value int = 5) AS SELECT Value=@Value"); var profiled = new ProfiledDbConnection((DbConnection)connection, MiniProfiler.Current); var result = profiled.Query<int>("InsightTestProcMiniProfiler", new { Value = 1 }).First(); Assert.AreEqual((int)1, result); } }
public void TestProfiledStoredProcWithParameters() { using (SqlTransaction t = _connection.BeginTransaction()) { _connection.ExecuteSql("CREATE PROC InsightTestProc (@Value int = 5) AS SELECT Value=@Value", transaction: t); var profiled = new ProfiledDbConnection(_connection, MiniProfiler.Current); var result = profiled.Query<int>("InsightTestProc", new { Value = 1 }, transaction: t).First(); Assert.AreEqual((int)1, result); } }
/// <summary> /// The EF code first. /// </summary> /// <returns>the entity framework code first view.</returns> public ActionResult EFCodeFirst() { int count; int? newCount = null; EFContext context = null; using (MiniProfiler.Current.Step("EF Stuff")) { try { using (MiniProfiler.Current.Step("Create Context")) context = new EFContext(); // this is not correct, as the count from this assignment is never actually used using (MiniProfiler.Current.Step("First count")) count = context.People.Count(); using (MiniProfiler.Current.Step("Insertion")) { var p = new Person { Name = "sam" }; context.People.Add(p); context.SaveChanges(); } // this count is actually used. using (MiniProfiler.Current.Step("Second count")) count = context.People.Count(); const string sql = "Select count(*) from People"; using (MiniProfiler.Current.Step("Get Count from SqlQuery Method - no sql recorded")) { newCount = context.Database.SqlQuery<int>(sql).Single(); } using (MiniProfiler.Current.Step("Get Count using ProfiledConnection - sql recorded")) { using (var conn = new ProfiledDbConnection(context.Database.Connection, MiniProfiler.Current)) { conn.Open(); newCount = conn.Query<int>(sql).Single(); conn.Close(); } } } finally { if (context != null) { context.Dispose(); } } } return Content(string.Format("EF Code First complete - count: {0}, sqlQuery count {1}", count, newCount)); }