Overview: I need to display different tables per year level from the students database table. When the administrator click the button for 1st year it will display all 1st year students (other filtering and sorting are in table). Also, it will also act as service to other apps that's why i cannot just use javascript/html on this (i've tried too slow). This is a report generation/query app for a sample school project.
Other apps must access it in a url like: http://localhost:6342/Students/GetYearLvl(1)
There are four html display tables: 1st year, 2nd year, 3rd year, and 4th year and each students profile when clicked on the table
I was able to do the YearLvl but when i tried to load a specific user it doesn't show
//Get ALL STUDENTS -- Required
public IQueryable<RequestStudents> Get()
{
StudentsModelContainer context = DbContextFactory<StudentsModelContainer>.Create();
var result = context.RequestStudentSet.Where(x => x.YearLvl == 1);
return result;
}
//
public IQueryable<RequestStudents> Get(int yearLevel)
{
StudentsModelContainer context = DbContextFactory<StudentsModelContainer>.Create();
if (yearLevel == 1 or yearLevel == 2 or yearLevel == 3 or yearLevel == 4){
var result = context.RequestStudentSet.Where(x => x.YearLvl == yearLevel);
return result;
}
else
{
var result = context.RequestStudentSet.Where(x => x.YearLvl == yearLevel);
return result;
}
}
When i try first or default it gives error like cannot convert RequestStudentSet.
Please do help. Not quite familiar in ASp.net C# MVC
.FirstOrDefault()(and what is the point of yourif/elseblock in the 2nd example - both do exactly the same thing).ToList< RequestStudentSet>()IQueryable<T>is a collection, you want a single value, so you cannot use it to return a single value