I am using MVC4 and C# and I'm trying to build and array in the view while I am looping through my model, for some reason I am getting a "Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding." It works fine if I remove the part where I try to build the arrays arr1 and arr2 and send them to the method called ArrTotal. This seems like a no brainer, no idea why it would cause a timeout. it should be building the arrays during the same query as before, and all that the method ArrTotal does is to add values from the two arrays together, no new query should be taking place to cause the server to timeout.
@model Tuple<Namespace.Models.Class1[], Namespace.Models.Class2[]>
....
@{
int i, x = 0;
int[] arr1;
int[] arr2;
}
@foreach (var item in Model.Item1)
{
arr1[i] = item.count;
<tr>
<td>@item.year</td>
<td>@item.month</td>
<td>@item.count</td>
</tr>
i++;
}
....
@foreach (var item in Model.Item2)
{
arr2[x] = item.count;
<tr>
<td>@item.year</td>
<td>@item.month</td>
<td>@item.count</td>
</tr>
x++;
}
....
@{
int[] total = Namespace.Models.GetTotal.ArrTotal(arr1, arr2);
}
@foreach (var t in total)
{
<tr>
<td>@t</td>
</tr>
}
Edit- some more information: This is the controller where I am running two queries:
var start = DateTime.Today.AddMonths(-15);
var query1 = (from t in db.table1
where t.ExportTemplate == "template1" && t.LogDate >= start
group t by new { Year = t.LogDate.Year, Month = t.LogDate.Month } into tg
orderby tg.Key.Year, tg.Key.Month
select new Class1
{
year = tg.Key.Year,
month = tg.Key.Month,
count = tg.Select(s => s.ObjectGUID).Distinct().Count()
}
);
var query2 = (from t in db2.table2
where t.UserID == 3 && t.RequestID == 3 && t.ErrorID == 0 && t.LogDate >= start
group t by new { Year = t.LogDate.Value.Year, Month = t.LogDate.Value.Month } into tg
orderby tg.Key.Year, tg.Key.Month
select new Class2
{
year = tg.Key.Year,
month = tg.Key.Month,
count = tg.Select(s => s.GID).Distinct().Count()
}
);
return View(System.Tuple.Create(query1.ToArray(), query2.ToArray()));
its the return View that times out. Like I said, it works as long as I dont try to build the arrays from the view