I have an WEB SQL in Windows Azure Server, and I need search an item in a table with 40.000 rows. The execution time of the query is one minute, too long for a web app (or any kind of application..). What ai do for reduce this time?
My question is similar to this: Entity Framework Very Large Table to List , but the answer is no acceptable because the method of paging is large too.
Code with search:
public ActionResult SearchNcm(string typeSearch, string searchString)
{
var ncms = repository.VIEWNCM.ToList();
if (Request.IsAjaxRequest())
{
if (!String.IsNullOrEmpty(searchString))
{
switch (typeSearch)
{
case "cod":
ncms = ncms.Where(e => e.CODIGO_LEITURA.ToLower().Contains(searchString.ToLower()) || e.CODIGO.ToLower().Contains(searchString.ToLower())).ToList();
break;
default:
ncms = ncms.Where(e => e.DESCRICAO.ToLower().Contains(searchString.ToLower())).ToList();
break;
}
}
}
return PartialView("BuscarNcm", ncms);
}
Not an answer but I need the space to expand on my comment above:
Remember that IQueryable and IEnumerable won't do anything until you either iterate or call ToList(). That means you can do things like:
var ncms = repository.VIEWNCM; // this should be IQueryable or IEnumerable - no query yet
if(Request.IsAjaxRequest())
{
if(!string.IsNullOrEmpty(searchString))
{
switch(typeSearch)
{
case "cod":
// No query here either!
ncms = ncms.Where(e => e.CODIGO_LEITURA.ToLower().Contains(searchString.ToLower()) || e.CODIGO.ToLower().Contains(searchString.ToLower()));
break;
default:
// Nor here!
ncms = ncms.Where(e => e.DESCRICAO.ToLower().Contains(searchString.ToLower()));
break;
}
}
}
}
// This is the important bit - what happens if the request is not an AJAX request?
else
{
ncms = ncms.Take(1000); // eg, limit to first 1000 rows
}
return PartialView("BuscarNcm", ncms.ToList()); // finally here we execute the query before going to the View
You probably also need a default filter if the searchString is empty
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.