Let's take this bit of code as an example:
string aliSpReqs = String.Empty;
foreach (var item in dc.TaskRelations.Where(tableRaletions =>
tableRaletions.TaskId == taskID
&& tableRaletions.RelTypeId == 13))
{
aliSpReqs += item.RefAliSpReq.shortdesc + "; ";
}
return aliSpReqs.Substring(0, aliSpReqs.Length - 2);
You're concatenating strings in a loop. That's a bad idea. Instead, try this (assuming .NET 4):
var query = c.TaskRelations.Where(r => r.TaskId == taskID
&& r.RelTypeId == 13))
.Select(r => r.RefAliSpReq.shortdesc);
return string.Join("; ", query);
In .NET 3.5 you'd need to use this instead:
var query = c.TaskRelations.Where(r => r.TaskId == taskID
&& r.RelTypeId == 13))
.Select(r => r.RefAliSpReq.shortdesc);
return string.Join("; ", query.ToArray());
Admittedly I can't tell whether that's actually what's making this slow or not - but it could well be, if there are a lot of strings.
As an aside, this is a terrible idea:
catch
{
return String.Empty;
}
Catch specific exceptions instead - or in most cases, just let the exception propagate to the caller. At the very least you should log the exception so you know what's going wrong.