I am making a program for a university that grabs active students and then spits out a report for other processes to use.
One of the important functions is to see if a student has graduated or not.
- If a Student graduated and is not coming back, they are not considered an active student.
- If they graduated and are coming back or didn't graduate and are coming back for another semester, they are considered active.
When a student passes through the main function, it takes about 5 seconds to run it through the process. I found that the most time taking part of the process comes from an IQueryable.First() in this function.
public static bool ContinuingEducation(string v)
{
    var TERMSSTU = from t in _DB.TERMs
                        join stu in _DB.STUDENT_TERMS_VIEWs
                        on t.TERMS_ID equals stu.STTR_TERM
                        where v == stu.STTR_STUDENT
                        orderby t.TERM_START_DATE descending
                        select new { startdate = t.TERM_START_DATE };
    var graduation = from a in _DB.ACAD_CREDENTIALs
                         where v == a.ACAD_PERSON_ID
                         orderby a.ACAD_COMMENCEMENT_DATE ascending
                         select a;
    if (graduation.Count() > 0 && TERMSSTU.Count() > 0)
    {
        if (TERMSSTU.First().startdate > graduation.First().ACAD_COMMENCEMENT_DATE) // the problem is here
            return true;
    }
    return false;
}
I do not know why it takes so long here. Is there a better way to write out this function so it is faster?
 
     
     
     
    