I have written a SQL query that works just fine, but am having a little trouble with the conversion to LINQ. Here is the SQL:
SELECT
CourseID,
CourseName,
CreditHours,
CPTRequired,
COTRequired,
CPTElective,
COTElective
FROM
Courses
WHERE
(CPTRequired = 'true')
AND
(CourseID NOT IN
(SELECT
Courses_1.CourseID
FROM
Courses AS Courses_1 INNER JOIN
Sections ON Sections.CourseID = Courses_1.CourseID INNER JOIN
Enrollment ON Enrollment.SectionID = Sections.SectionID INNER JOIN
Students ON Students.StudentID = Enrollment.StudentID
WHERE
(Students.StudentID = '11110004')))
And here is what I have written so far with LINQ:
Dim maj = (From c In connect.Courses _
Where c.CPTRequired = "True" _
Select c.CourseID, c.CourseName, c.CreditHours).Except _
(From en In connect.Enrollments _
Join s In connect.Sections On en.SectionID Equals s.SectionID _
Join cs In connect.Courses On s.CourseID Equals cs.CourseID _
Join st In connect.Students On en.StudentID Equals st.StudentID _
Order By cs.CourseName _
Where st.StudentID = StudentID _
Select cs.CourseID)
When executed the LINQ statement throws the following errors.
System.InvalidCastException was unhandled Message="Unable to cast object of type 'System.Data.Linq.DataQuery'1[System.String]' to type 'System.Collections.Generic.IEnumerable'1 [VB$AnonymousType_6'3[System.String,System.String,System.Nullable`1[System.Int32]]]'." Source="Final Project"
What am I missing? I am brand new to LINQ, so please be gentle!!