Every query is taking 5 seconds to run.
I'm just trying to make simple querys to the database from my site and it's taking too long.
This is the query and how i'm measuring the time
var sw = new Stopwatch();
sw.Start();
var leg = db.Legislacaos.Where(x => x.leg_ativo).ToList();
sw.Stop();
ViewBag.sw = sw.Elapsed;
When I do the query in "phpMyadmin" SELECT * FROM 'legislacao' WHERE 'leg_ativo' =1
it takes no time at all but it takes 5 second per query in my site.
I have a page that has 4 querys that takes 20 seconds to load. The time is stable, I tried in tables with 20,100,300,1000 records(in different tables), all of them used the same amount of time. Also, tried to add "leg_ativo" as an index but there was no difference.
I don't know if it's necessary but some background code:
public class LegislacaosController: Controller
{
private Context db = new Context();
public ActionResult Create()
{
var sw = new Stopwatch();
sw.Start();
ViewBag.Leg = db.Legislacaos.Where(x => x.leg_ativo).ToList();
sw.Stop();
ViewBag.sw = sw.Elapsed;
return View();
}
//...
}
Context-
public class Context : DbContext
{
public Context() :base("smagnus_tester")
{
Configuration.ProxyCreationEnabled = false;
Database.SetInitializer(new
DropCreateDatabaseIfModelChanges<Context>());
}
public DbSet<Legislacaos> Legislacaos{ get; set; }
//...
}
Model-
public class Legislacao
{
[Key]
public int leg_id { get; set; }
[Required(ErrorMessage = "Preencha o campo Legislação")]
[DisplayName("Legislação")]
[StringLength(255)]
public string leg_nome { get; set; }//name
[Required(ErrorMessage = "Preencha o campo Resumo")]
[DisplayName("Resumo")]
[StringLength(255)]
public string leg_resumo { get; set; }//resume
[DisplayName("Anexo")]
public string leg_anexo { get; set; }//file
[DefaultValue(true)]
[DisplayName("Ativar?")]
public bool leg_ativo { get; set; }//active
public virtual ICollection<Legislacao_Risco> Legislacao_Riscos { get; set; }
}
Database config
Microsoft-IIS/7.5
Client version MySQL: 5.0.51a