Reading Agility MVC

2

I have an application in MVC 4 that has no addition / deletion / editing operation, it only reads and makes data available (according to filters).

The data comes basically from 4 views .

  • Being the first of about 1,500 records - instant reading via query
  • The second of about 15 thousand - reading about 14 seconds via query
  • The third of about 30 records - instant read via query
  • The fourth of about 1.3 thousand records - instant read via query

Each view has its own model. Consecutively, in every% required%, I call the required domain.

I previously worked similarly to this example:

var bdModelA = new SegundaViewEF(Contexto); // View da query de 14 segundos
var Todos = bdModelA.ListarTodos();
var Quantidade = Todos.Count();
var NF = Todos.Where(x => x.Tipo == "NF");
var NCC = Todos.Where(x => x.Tipo == "NCC");
var QuantidadeNF = NF.Count();
var QuantidadeNCC = NCC.Count();

foreach(var Item in NF){
// codigo aqui
}

foreach(var Item in NCC){
// codigo aqui
}

I noticed slow, I started working like this:

var bdModelA = new SegundaViewEF(Contexto);
var Todos = bdModelA.ListarTodos();
var QuantidadeNF = 0;
var QuantidadeNCC = 0;
var Quantidade = 0;

foreach(var Item in Todos){
Quantidade++;
if(Tipo == "NF"){
QuantidadeNF++;
//Codigo aqui
}else if(Tipo =="NCC"){
QuantidadeNCC++;
//Codigo aqui
}
}

It was slow.

I would like to know if the best practice is the one described in the first example or the second and if there is any limitation of the MVC with respect to reading PartialView , since I always worked with table reading.

I call one of three different domains in each of my PartialViews, the one of the largest query (14 seconds), I call at least 4 times. I have about 7 to 8 PartialView.

My application takes about 8 minutes to open (VPN connection) and 5 minutes via direct connection.

What can I do to improve?

    
asked by anonymous 28.01.2016 / 19:27

1 answer

1
  

I would like to know if the best practice is the one described in the first example or second and if there is any limitation of MVC with regard to view reading, since I have always worked with table reading.

Neither. It is the repetition of the already misleading error of encapsulating the context. It will not work right because so you take out the code options to create already optimized queries for each query you will make. As it stands, all the readings will be TABLE SCAN .

What I would do:

// var bdModelA = new SegundaViewEF(Contexto);
// var Todos = bdModelA.ListarTodos();
// var Quantidade = Todos.Count();
var Todos = Contexto.SegundaViewEF.AsQueryable();
var NF = Todos.Where(x => x.Tipo == "NF").ToList();
var NCC = Todos.Where(x => x.Tipo == "NCC").ToList();
var QuantidadeNF = NF.Count();
var QuantidadeNCC = NCC.Count();

foreach(var Item in NF){
// codigo aqui
}

foreach(var Item in NCC){
// codigo aqui
}
  

What can I do to improve?

There is something else that can be done: Install MiniProfiler.Mvc4 (serves MVC5 as well) and confer consultations.

Here's how to set up the project here .

    
28.01.2016 / 19:54