我有一个sql存储过程,返回926行,每行有238列,该存储过程需要1秒才能返回。现在我尝试在ASP.NET MVC中运行存储过程并在名为Report的模型类中返回结果,之前请参阅我的方法,但是它运行此代码并将项目返回到它永远需要的类中,有时会冻结我的浏览器。我将如何加快这一进程?
public List<KeyValuePair<object, List<Report>>> GetReportTest(string area, int? isAlphabeticalSort)
{
List<KeyValuePair<object, List<Report>>> ReportData = new List<KeyValuePair<object, List<Report>>>();
try
{
using (connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("GetTasks", connection))
{
command.CommandType = CommandType.StoredProcedure;
SqlParameter parameter1 = new SqlParameter(“@area”, SqlDbType.VarChar);
parameter1.Value = area;
parameter1.Direction = ParameterDirection.Input;
command.Parameters.Add(parameter1);
SqlParameter parameter2 = new SqlParameter("@isAlphabeticalSort", SqlDbType.Bit);
parameter2.Value = isAlphabeticalSort;
parameter2.Direction = ParameterDirection.Input;
command.Parameters.Add(parameter2);
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
var model = reader.GetValue(0).ToString();
List<Report> report = new List<Report>();
for (int i = 1; i < reader.FieldCount; i++)
{
RedBlue item = new RedBlue();
if (reader.GetName(i).ToString().Contains("Task"))
{
item.task = reader.GetValue(i).ToString();
i++;
}
if (reader.GetName(i).ToString().Contains("BID"))
{
item.baselinefinish = reader.GetValue(i).ToString();
i++;
}
if (reader.GetName(i).ToString().Contains("AID"))
{
item.actualenddate = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString().Contains("ClosingDate"))
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString().Contains("DaysToClosing"))
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString().Contains("ScheduleVariance"))
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString().Contains("DaysOfConstruction"))
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString().Contains("IDNOTES"))
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
if (reader.GetName(i).ToString() == "PDIToClose")
{
item.baselinefinish = reader.GetValue(i).ToString();
redBlue.Add(item);
}
}
ReportData(new KeyValuePair<object, List<Report>>(model, report));
}
}
}
}
return ReportData;
}
finally
{
connection.Close();
}
}