I have a mvc 3 app that uses EF. In one function I need to get a count of rows that match a statement. I thought I could just do it like this:
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
But that stays at 0 even when there are 40 records that match the criteria.. I think I have the right idea I just need to change the syntax a little.. Anyone know where this is failing?
Dim _CurrRegistrants As List(Of reg_classes) = db.reg_classes.ToList
For Each Course In _courses.Where(Function(a) a.course_day = "Tuesday")
Dim _CurrCourse As cours = Course
Dim _ClassCount As Integer = _CurrRegistrants.Where(Function(c) c.tues_class = _CurrCourse.course_ref).Count
From looking at the first example of the code it appears that you might be pulling data from somewhere other than the data context. Add the data context to your query and you should then be able to access to records which you are attempting to compare each other to.