1
2つのイベントのいずれかにいたすべての生徒のリストを取得したいとします。ここに私の機能は、出席者のリストを取得するためにです:2つの関数呼び出しが含まれています
Private Function AttendanceList(ByVal Mode As AttendanceListLookupMode, ByVal AttendaceTypeID As Integer, ByVal EventID As Integer, ByVal EventOccurenceDate As Date) As IEnumerable(Of Integer)
'Get the attendance table for specified event
Dim resultSet = From a In db.tblAttendances
Where a.tblEventOccurence.EventID = EventID _
And a.tblEventOccurence.EventOccurenceDate = EventOccurenceDate
'Apply mode filtering
Select Case Mode
Case AttendanceListLookupMode.AttendanceTypeIs
resultSet = resultSet.Where(Function(x) x.tblAttendanceType.AttendanceTypeID = AttendaceTypeID)
Case AttendanceListLookupMode.AttendanceTypeIsNot
resultSet = resultSet.Where(Function(x) x.tblAttendanceType.AttendanceTypeID <> AttendaceTypeID)
End Select
'Return the student records
Return resultSet.Select(Function(x) x.StudentID)
End Function
Private Enum AttendanceListLookupMode
AttendanceTypeIs
AttendanceTypeIsNot
End Enum
は今、私はどちらかのイベントが次のように出席したかどうかを確認するためにクエリでそれを使用したい:
'All students
Dim resultSet = From s In db.tblStudents
resultSet = resultSet.Where(Function(x)
AttendanceList(AttendanceListLookupMode.AttendanceTypeIsNot,
CommonAttendanceTypeIDs.Absent,
CommonEventIDs.Learning,
ForDate).Contains(x.StudentID)
Or
AttendanceList(AttendanceListLookupMode.AttendanceTypeIsNot,
CommonAttendanceTypeIDs.Absent,
CommonEventIDs.Basketball,
ForDate).Contains(x.StudentID)
End Function)
私はこれをコンパイルしようとすると、私は
Error 1 Overload resolution failed because no accessible 'Where' can be called with these arguments:
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of tblStudent, Integer, Boolean))) As System.Linq.IQueryable(Of tblStudent)' defined in 'System.Linq.Queryable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of tblStudent, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Linq.Expressions.Expression(Of System.Func(Of tblStudent, Boolean))) As System.Linq.IQueryable(Of tblStudent)' defined in 'System.Linq.Queryable'.
Extension method 'Public Function Where(predicate As System.Func(Of tblStudent, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of tblStudent)' defined in 'System.Linq.Enumerable': Nested function does not have a signature that is compatible with delegate 'System.Func(Of tblStudent, Integer, Boolean)'.
Extension method 'Public Function Where(predicate As System.Func(Of tblStudent, Boolean)) As System.Collections.Generic.IEnumerable(Of tblStudent)' defined in 'System.Linq.Enumerable'.
私はラムダの声明を一切受けないでしょう、私はそれを認識しませんでした。私は文のラムダを式ラムダにするためにVBの行継続文字_を使うことができました。 –
ああ、VS2008を使用しています、ごめんなさい。その場合、複数行のラムダ構文は利用できないので、あなたがやったことをやるほうがいいです。 :-) –