我需要将此代码转换为c#。我在第8行遇到问题。 公共类数据库
Public Function GetCourses(StudentID As Integer) As List(Of Course)
Dim xEntity As New MyLearningEntities
Dim xList As New List(Of Course)
Dim xStudent As Student
xStudent = (From x In xEntity.Students.Include("Courses") Select x Where x.StudentID = StudentID).FirstOrDefault
If xStudent IsNot Nothing Then
Return xStudent.Courses.ToList
Else
Return xList
End If
End Function
答案 0 :(得分:0)
您可以使用此link将C#转换为VB.Net,反之亦然
public List<Course> GetCourses(int StudentID)
{
MyLearningEntities xEntity = new MyLearningEntities();
List<Course> xList = new List<Course>();
Student xStudent = default(Student);
xStudent = (from x in xEntity.Students.Include("Courses") where x.StudentID == StudentID select x).FirstOrDefault();
if (xStudent != null)
return xStudent.Courses.ToList;
else
return xList;
}