Thanks for pointing me in the right direction. You're right, from what I have seen it makes more sense to split it up. When i had the grouping and SUM in all in the same statement as the rest of my LINQ it took a good amount of time to run.
Doing a foreach on the results seems to be a better way of solving this.
This is what I have right now in case it helps anyone else out there:
<pre lang="xml">public Dictionary<string, int> getProgramFocusData(DateTime FYstart, DateTime FYend)
{
DataClasses1DataContext db = new DataClasses1DataContext();
var matchingRequests = from t in db.Tables
join c in db.Codes on t.ID equals c.Level1_ID
join r in db.Requests on c.Request_ID equals r.ID
join cs in db.Coding_Sheets on r.Coding_Sheet_ID equals cs.ID
where c.Table_Master_ID.Equals("104")
&& r.Disposition.Equals("Approved")
&& r.Disposition_Date > (FYstart)
&& r.Disposition_Date < (FYend)
select new programFocus((string)t.Description.ToString(), Convert.ToInt32(r.Grant_Amount));
List<programFocus> programs = (List<programFocus>)matchingRequests.ToList();
Dictionary<string, int> Results = new Dictionary<string, int>();
foreach (programFocus p in programs)
{
string desc = p.PRGFOCUS;
if (p.PRGFOCUS != null && !Results.ContainsKey(desc))
{
var subresults = from sub in programs where sub.PRGFOCUS == desc select sub;
int dollars = 0;
foreach (programFocus subsub in subresults)
dollars += System.Convert.ToInt32(subsub.DOLLARS);
Results.Add(desc, dollars);
}
}
return Results;
}
I am in no way claiming this the best way to do this, in fact if you know of a better way of accomplishing this, please let me know.