0

So what I want to do is to return a list of all the students personal informations, but i want to do that depending on the value of their status on another table, what should I do, what have now is:

public ActionResult AdminPanel()
    {
        List<student> status1 = db.students.Where(u => Convert.ToInt32(u.status) == 1).ToList();
        return View(db.studentspersonalinformations.OrderBy(u => u.DNI).ToList());
    }

What I get as a return there is all the students, but what I want is to get the students that have status 1 on the table "students", I can't put a .Where() since it is from another table and haven't found anything online that could help me

MiGu3X
  • 119
  • 1
  • 15

1 Answers1

0

You may need to use a Join

var result = enumerableOfSomeClass
    .Join(enumerableOfSomeOtherClass,
          sc => sc.Property1,
          soc => soc.Property2,
          (sc, soc) => new
                       {
                           SomeClass = sc,
                           SomeOtherClass = soc
                       });

From How to do a join in linq to sql with method syntax?

This has not been tested but it should look like something like this

public ActionResult AdminPanel()
{
    List<student> status1 = db.students
                .Join(
                    sc => sc.studentID,     //Or whatever Information is linking your table together
                    soc => soc.studentID,
                    (sc, soc) => new
                    {
                        students = sc,
                        SomeOtherClass = soc
                    });
                .Where(u => Convert.ToInt32(sc.status) == 1).ToList();
            return View(db.studentspersonalinformations.OrderBy(u => u.DNI).ToList());
}
Community
  • 1
  • 1
Alegrowin
  • 321
  • 1
  • 14