public ActionResult Index(PascalsPyramidModel model) { if (ModelState.IsValid) { using (var db = new YouConfDbContext()) { //Run it once to warm it up, that way we're actually testing the proc, and not the connection to SQL and Entity framework etc var nthRow = db.Database.SqlQuery <string>("exec GetPascalTriangleNthRow @RowNumber", new SqlParameter("@RowNumber", model.RowNumber)).First(); // Create new stopwatch Stopwatch stopwatch = new Stopwatch(); // Begin timing stopwatch.Start(); for (int i = 0; i < 10; i++) { db.Database.SqlQuery <string>("exec GetPascalTriangleNthRow @RowNumber", new SqlParameter("@RowNumber", model.RowNumber)).First(); } var elapsed = stopwatch.Elapsed; ViewBag.TotalTimeElapsed = elapsed; ViewBag.NthRow = nthRow; return(View(model)); } } return(View(model)); }
public void SetupTest() { //Database.SetInitializer<YouConfDbContext>(null); Database.SetInitializer(new DropCreateDatabaseAlways <YouConfDbContext>()); using (var context = new YouConfDbContext()) { context.Database.Initialize(true); } _context = new YouConfDbContext(); }